Various bug fixes

Hi Simson,

First, thank you for your work on afflib.  We are using the library in a commercial data recovery/imaging product and have encountered various problems (mostly related to error handling) along the way.  Here are the changes we've made to fix said problems.  Please feel free to merge all of them or pick and choose, as you like.

Sincerely,
John Lindgren
CPR Tools, Inc.