updated gateway connect code