Improved exception reporting.  Some refactoring and fixes.