added writing to data to file, and some more comments