Adds lazy initialization to loading-manager

Loading manager could encounter circumstances where its references to
the DOM were not valid (possibly because the script ran before the DOM
completely loaded). This adds lazy initialization of the DOM reference
variables so that their value is checked before they are used by the
script's logic.