Pulled universal objects defined at the start of main out into globally-scoped variables.
Pulled some initialisation work out into an init() function, which is called at the start of main().