added writing to file method