use sort while checking last tag