Fixed some issues with saving files on linux systems.

To do:
General code cleanup
More unit tests