more refactoring
+ added debug output