Updates to compute_gain.