Got debug printing more robust, cleaned up, and printing nicely. Also
fixed some bugs found along the way.