Updated error handling.