changed some variables to global variables