changed local variables to account for global variables