plug flow refactoring