optimize flow