REV A of complete state machine for code review.