Updating the logic of the DocumentManager and extending some tests.