Add error handling

Resolve #7