moved global vars to top