initial unit tests, refactor, docs