refactored flow.