Fix handling of deeply nested documents.