Improve error handling interface

Fixes #49