cleanup and debug printing code