Fixed exception if an output file was used multiple times, updated unit tests