Added functionality for saving to file.