added error messages to code