more refactoring + more unittests