fix issues with global vaiables