state machine for butterfly