Added main state machine.