Refactored and deduplicated debug setup