rearranging order in which pipes are closed