Improve error handling and messaging.