Fix global variable issue