Factor out and test reading from file
Test and fix writing to file