Noted that previous submission would not work if I changed some of the parameters. Corrected code in the for loop.