refactoring out debug message generation as function