fixed global var issue