Based on finate state machine.