Improve error handling and messages.