Revert "Removed some unused code."

This reverts commit 093b2f561cf3c7b51d05785b7dff5494401e6a5c.
Moved some logic into onload function.

Moved some of the logic into a window load function. Makes it easier to
keep track of everything running.