added timer and state machine to handle events