Moved global vars to end of file