Implements merge sort