More work on error handling. Fixes issue #9.