Changed pipe handling loop