fix recursive interrupts, and more improvements to code