Replace sort_with_context with sort_by.

sort_by takes a closure and should be more flexible.
sort_with_context was less flexible than I had hoped;
I couldn't implement sort_by using it.