Refactoring pipeline code