refactored some code in DocumentRepository