updated error messages and error checking.