simplify get_median function