Refactor pipeline code