modified iterative version of merge sort