Minor fix to always sort even if allocation fails in get_refs