Adds write functionality and cleanup of unit-test.
Improvements to behaviour surrounding directories, minor bug fixes and adds integration tests.