Fix for bug 1073816 and some improvements to debug utilities.