Fix global variable scope