finished the median calculations