Improved the sorting