Improved debug handling