Fix median calculation formula