Minor code cleanup and improved debug printing.