Bug fix: crash when adding a document.