Added functionality for writing to file.