Fix sort function.