Fixed file reading and writing