added tests and some small refactors