this whole procedure still seems a bit off when being called in return_gateway_groups_array(), maybe we should move this to a more sane location at some other point in time: