Added logic to create documents, code refactoring and unit tests