Problem with for loop. See commented code