Fix gain calculation