corrected some leakage to global scope.