fix ugly global variable bug