Fix median calculation.