small fixes + refactoring