Added gain condition and changed threshold