Global loop variable changed to local