Add error handling. closes #1