Added condition in error logging to prevent nonobject error.