correct a bug in sort_by