some more fixes + refactoring