fix in writing to file