Completed sort implementation.
Fix for issue with descending sort.