Some minor code adjustments
Global variable refactoring