initial pipe impl - needs testing and some refactoring to reduce complexity and further reuse etc