cleaner template compilation; refactored out some globals