Refactored DEBUG handling