fixed bounds problem for for loop