Error handling

Fixes #61