Improve error handling to include all possibilities.