refactoring + some extra tests