fix gain implementation