refactoring + more tests added