updated gateway code