Add correct error handling. Closes #3.