added error checking and changed error messages