added debug parameter
refactoring (inbetween commit)
refactoring