Working code with interrupts