file-save duplication refactoring