Fix sorting behavior for items at end of a list

Fixes #27