flow refactoring