minor refactoring + 1 bugfix