Refactor/reimplement and test checking of document existence.
Refactor/reimplement and test updating of documents.