refactoring + fixed test