Improved debug logging