Fixing global variable

Adjusted use of global variables to use the $GLOBALS array instead which gives more clarity about its use and prevents inserting another variable into the scope.