Fix handling of spaces in filepaths

Might still be some corner cases but should put us on the right path to fixing any remaining issues here.