fixed global variable bug