refactoring + more tests!