fix error handling in pull request #2