Fix sorting of items

These are the fixes for sorting bugs filed in bugzilla.