modified merge_sort algorithm to stable version