Better error handling. Closes #143.