Small refinement to parse_document