Removed the use of global vars. Bad, bad initial idea.