Refactored parts of the flow.