Implements list sorting.