def calculate_median(vals)
    return nil if vals.empty?

    vals.sort!
    (vals[(vals.length - 1) / 2] + vals[vals.length / 2]) / 2.0