removed gain and fixed some errors