fixed msort function