Redid error handling, ensured db connected before proceeding.

Also cleaned up whitespace and fixed some minor jshint nits.
Merge pull request #1 from othiym23/master

Rework error handling and put top-level error handling in a domain.