fixing file read/write