Moved closing pipes into a helper