Refactored the flow