Fix median sort error