Fix median calculating