add generic version of merge sort. fix out-of-bounds slice in non-generic merge sort.