factor out clearInterrupts

reformat, & add some comments