Make DocumentFactory more null resistant