Improved debug code