Fixed another bug in sorting