slight refactoring, minor bugfixes