refactors flow.