Fixed some bugs, cleaned up logic and added support for spaces in paths