more internal refactoring
more tests