got those gain(s algorithm working)