Refactor pipeline

Phase 1.