Fix sorting. close #144

See #143 for description.