Added gain as a parameter