rewritten the merge sort algorithm to match default (also bas) implementation