Refactoring by removing the global variables and moving them as fields.