cleanup + fixes + tests
unit tests