fix principal sorting