refactored code into one global variable