corrected the median function