State machine.