small fixes and refactoring