Pipeline function refactored and tested