Fixed global variables issues