Restructured the code to remain as a global variable.