optimize is_doc_ref and Document.