Fix/file refactor

Small refactor of the file output and added more test coverage for it.