finish msort helper functions