Added sorting before checking matching t.ids