error check and error messages added