small fixes and refactoring in progress