Fixed problem with for loop