Changed global vars to local