Format update.

Formatting update only.  Adding proper phpDocs and indentation of major
block.
Refactoring new exception handling code

Make the new JSON error checking API slightly more unobtrusive.  Also
reformatting code.
Reformatting code