minor bugfixes and refactoring