more error handling and fixed an error message issue