refactoring, small fixes