added a check for a KeyError, and error message.