fixed broken for loop