Generic sort + merge sort optims