Add Gain and threshold handling