cdrenhancementTable = {}
     
function AddUnitEnhancement(unit, enhancement, slot)
    if not slot then return end
    local id = unit:GetEntityId()
    local unitEnh = SimUnitEnhancements[id]
    
    local bp = unit:GetBlueprint()
    local iscommander = false
    if bp.BlueprintId == 'uel0001' 
		 or bp.BlueprintId == 'ual0001'
		 or bp.BlueprintId == 'url0001'
		 or bp.BlueprintId == 'xsl0001' then
			iscommander = true
    end
    
    if unitEnh then
        if iscommander then 
        	if not cdrenhancementTable[id] then 
        		cdrenhancementTable[id] = {}
        	end
        	cdrenhancementTable[id][slot] = enhancement
        	cdrenhancementTable[id][enhancement] = enhancement
        	SimUnitEnhancements[id] = cdrenhancementTable[id]
        else         
        	SimUnitEnhancements[id][slot] = enhancement
        end
    else
        SimUnitEnhancements[id] = {}
        if iscommander then 
        	if not cdrenhancementTable[id] then 
        		cdrenhancementTable[id] = {}
        	end
        	cdrenhancementTable[id][slot] = enhancement
        	cdrenhancementTable[id][enhancement] = enhancement
        	SimUnitEnhancements[id] = cdrenhancementTable[id]
        else         
        	SimUnitEnhancements[id][slot] = enhancement
        end
    end
    SyncUnitEnhancements()
end

function RemoveAllUnitEnhancements(unit)
	 	local id = unit:GetEntityId()
    local bp = unit:GetBlueprint()
    if bp.BlueprintId == 'uel0001' 
		 or bp.BlueprintId == 'ual0001'
		 or bp.BlueprintId == 'url0001'
		 or bp.BlueprintId == 'xsl0001' then
			cdrenhancementTable[id] = nil
    end
    SimUnitEnhancements[id] = nil
    SyncUnitEnhancements()
end