Basis for improved error handling.

Please review and merge.