implementing gain_ratio for #524