Method doesnt work as intended

I have this method, this method is called OnPointerClick from other script. It should remove item from slot and add new item to this slot. However it adds item to empty slot at first. But then, if i click another item, it removes item from slot, but not adding it.

    public void RemoveUpgrade(ItemSO item)
    {
        UpgradePanelSlot slot = upgradePanelSlots[0];
        UpgradePanelItem itemSlot = slot.GetComponentInChildren<UpgradePanelItem>();
        if (itemSlot != null)
        {
            Destroy(itemSlot.gameObject);
            Debug.Log("Good");
        }
        AddItemToUP(item);
    }

Fixed

    public void RemoveUpgrade(ItemSO item)
    {
        /*if (slotIndex < 0 || slotIndex > upgradePanelSlots.Length - 1)
        {
            return;
        }*/
        UpgradePanelSlot slot = upgradePanelSlots[0];
        UpgradePanelItem itemSlot = slot.GetComponentInChildren<UpgradePanelItem>();
        if (itemSlot != null)
        {
            Destroy(itemSlot.gameObject);
        }
        GameObject newItemGameObject = Instantiate(UpgradePanelPrefab, slot.transform);
        UpgradePanelItem inventoryItem = newItemGameObject.GetComponent<UpgradePanelItem>();
        inventoryItem.InitialiseItem(item);
    }