added gateway handling