Bug fixes to document retrieval