Fixing pipeline switching behaviour and adding tests