fix global variable bug