Updated writing to file