Added extra error handling.