Fixed the global variable problem