Refactored to take out the pipeline internals