fixed global variable problem