Fixed global variable bug