Add explicit error checking and exit on first error

Fixes #10