fixed timer interrupt and cleaned up code