fixed file reading and writing
merging changes