Moved global variables to globals infrastructure.
Less unnecessary dynamic memory usage.
Moved global variables to globals infrastructure.