added a FSM to maintain state and transitions (couldn't help it...).