fix inconsistent tie breaking in sort