Fix sorting behavior for items at end of a list (fixes #27)