Remove duplicated forening sort logic