Better path handling.

Using pardir, not using forward slashes, and some other refactoring for better clarity of what's going on.