Added functions to write to files