writing to file fix