small bug in for loop