Refactor out 'globals' from more functions