add unit tests
refactor public API, add unit tests