Updated merge_sort with ternary function