refactored out some globals