Added gain function