Made sorted index array better by skipping copying of array.