refactoring + tests fixes