fix gateway selection; the gateways were not sorted before at all (by connectivity)