added writing to file and timestamp