Some tweaks, fixes and removals of debug code