more performance improvements, bugfixes and small refactorings