Use common code for all file I/O