Fix global var problem