working version of insertionSort