Tests, cleanup

* add more tests
* minor refactor