Made the function to use global variables. It was throwing an error because it couldn't reslove the conflict