ENH: Better error handling

Designed to address #337.