Improved error handling/reporting.

Closes #12.