restore O(n*log(n)) complexity