Fix global variable in for