constantized the gateway constructor.   commonized code and removed duplication