fix global variable issues