Clean up file I/O implementation a bit