Make templates closer to where they're called
Remove some global variables