Proper exception handling

Fixes #2
Merge pull request #4 from coagulant/patch-1

Proper exception handling