Fix error handling. Closes #6.