minor refactoring and bugfixes