the regeneration and cooling flows travel in the opposite direction upstream when there is simultaneous heating and cooling in separate beds the normal process flow pattern will be adsorption downstream regeneration flow upstream and the cooling flow downstream contaminated feed gas is passed through a molecular sieve system to remove contaminants in one embodiment of the invention the system always operates with one adsorbent bed in adsorption mode one adsorbent bed in a regeneration or desorption mode in which a heated gas is passed through the adsorbent bed and one adsorbent bed is in cooling mode there can be more than the three adsorbents present in a system when the adsorbent bed that is in adsorption mode becomes saturated with impurities it is taken offline from the incoming contaminated feed gas and regenerated regeneration is accomplished by passing regeneration gases through a heater and then subsequently passing the resulting hot regeneration gases through the adsorbent bed it is preferred to heat the adsorbent bed at a specified rate after the spent regeneration gas leaves the adsorbent bed it is cooled to a specified temperature and then passed through a membrane element in the membrane system if necessary there is a phase separating vessel after the cooler to remove any condensed liquids a significant portion of the contaminants and some carrier gases pass through the membrane element into the permeate or waste stream to be discarded or flared off the residue gas passes out of the membrane without going through the membrane itself and retains the majority of the carrier gas and a lower concentration of contaminants than the permeate stream.