Improved sorting of list