optimize the flow