add unit test for documents, tiny bug fix