sort multiples gateways by `refs`