use state machine and register flow