fixed trying to get property of non object if agent exists