more fixes, refactoring