Refactor MergeSort and implement set_extremal_elements in O(n)

- Cleaned up test code