Added functionality to write to file.