optimized sorting, new runtime: O(n*log²(n))