Refactoring: Trying to get rid of globals