Improve error handling and get rid of a lingering fprintf().