small refactoring and bugfix

closes #296