refactored all the global variables, no testing