Note that optimize.py is primarily not my work, and is only included here for convience of access.
Simplify.py takes paths, breaks then apart (if they're not continuous) and then matches it's end points with other end points. It will swap the direction of a path if necessary.