Some modifications to sortByKey API.
Add documentation.