Remove some unnecessary use of globals