Simplified read/write file functions, added unit tests