more refactoring of the documents controller