Fix median bug