Refactored pipeline to work with streams