Global variables are now handled with care

this is patch by Matyas Novak