Fixed global variable problem