Updated the sorting of gradients.