Refactor out global variables