debug printer refactored