The client state machine