Apparently correct code to handle interrupts