changing global variables to local