Add some debug and bug handling code