fixed some global variable issues