Slightly more robust error handling.