Improve error handling interface

Fixes #49
Merge pull request #50 from gavacho/fix-error

Improve error handling interface