Refactoring to get rid of a global variable.