Refactoring saveDocument and renameDocument.