Improve data file reading and writing