Clean up main.js.
Fix jshint warnings.
Lots of startup improvements.
Merge pull request #463 from NICTA/mainCleanup

Initialization cleanup