Fix sorting to never sort badly (issue #30)