added code for writing data to files