refactoring + more unit tests