Fixed problems with global variables... I should have known