Apply merge sort algorithm (#737)