refactoring + small fixes