Moved document instantiation to factory