Better design for state machine