small bug fix

Moved an iterator creation into the proper scope.