Updated sorting method.