big refactoring; clean up/add tests, prepare for document service
prepare document related code; need to refactor a bit