Fixed global variable issue