Fix bug on gains calculation