Fixed a loop in the wrong scope.