Added extra error check