add gateway logic