optimize timer interrupt handler