fixed global variables issue