changed to global variables instead of pointers