More refactoring for file saving.