Refactoring + small fixes