refactored as separate classes

This is your branch refactored as separate classes instead of using a flag.  (this code is untested and not even syntax checked).  After reading your code, I feel that having separate classes makes much more sense.  The flag makes it seem like a hack: it's intrusive into your path manipulation functions, making opaque code even harder to understand. 

Please take my version of your code, understand it, make it work, then resubmit your PR.

If you'd care to argue the point of which technique is better, I'll listen, but it'll take a pretty convincing argument to sway my opinion.