finally got it working with interrupts