fixed global variable issue