Variable in global scope issue