First of all, I see you are new here. Welcome.

To handle interrupts, I suggest you look for Darrell Taylor's excellent posts on Instant Interrupts. They are a hit here you see. Moreover, they will avoid the code bloat and latency that ON INTERRUPT processing offers. Just looking through the posts on instant interrupts will reveal a lot of ideas on how to solve your problem.