Fixed issue with for loop