Small refactoring + fixed tests