You don't use it properly in the while loop. First you have a mismatch between group IDs in set_engine_par and find_mod - first is 0 the second is 1. You should just use your loop counter here instead. Also make sure that the LFO exists in all groups and that it has the same name. Also please use CODE tags to retain indentation of the code you paste.