Added extra error handling