extra error check and addition lines