def add_object object , level
      # see if we we came accross this before
      if( occurence = @objects[object.object_id] )
        #puts "reset level #{level} at #{occurence.level}" if occurence.referenced #== 19
        if occurence.level > level
          #always store the most shallow level
          occurence.level = level
        end
        # and only one Occurence for each object, create a reference for the second occurence
        unless occurence.referenced
#          puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 23
#          puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 19
          if object.respond_to? :rxf_reference_name
            reference = object.rxf_reference_name
            reference = reference.to_s.gsub(/\s|\W/ , "") #remove space and stuff
            if( @references.include?(reference) or reference.empty?)
              reference = "#{reference}-#{@counter}"
              @counter = @counter + 1
            end
          else
            reference = @counter.to_s
            @counter = @counter + 1
          end
          occurence.set_reference(reference)
          @references << reference
        end
        return nil
      end
      # if first time see, create and store Occurence
      @objects[object.object_id] =  Occurence.new( object , level )
      return object
    end
def add_object object , level
      # see if we we came accross this before
      if( occurence = @objects[object.object_id] )
        #puts "reset level #{level} at #{occurence.level}" if occurence.referenced #== 19
        if occurence.level > level
          #always store the most shallow level
          occurence.level = level
        end
        # and only one Occurence for each object, create a reference for the second occurence
        unless occurence.referenced
#          puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 23
#          puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 19
          if object.respond_to? :rxf_reference_name
            reference = object.rxf_reference_name
            reference = reference.to_s.gsub(/\s|\W/ , "") #remove space and stuff
            if( @references.include?(reference) or reference.empty?)
              reference = "#{reference}-#{@counter}"
              @counter = @counter + 1
            end
          else
            reference = @counter.to_s
            @counter = @counter + 1
          end
          occurence.set_reference(reference)
          @references << reference
        end
        return nil
      end
      # if first time see, create and store Occurence
      @objects[object.object_id] =  Occurence.new( object , level )
      return object
    end
add object (as occurence) if it doesn't exist
 return object or nil