Global variable problem solved