small fixes, refactoring