many bugfixes from refactoring