Array of Tilemaps misbehaving

I am creating a script that generates a 2d array of Tilemaps and then runs a specific function on them that will create “caves” with a Perlin function. It was only showing up on the top left Tilemap, so I tried to see where the function was actually working by making it remove all tiles it passes over and this is what I got.


The result I was expecting was all of the tiles to be gone. Why aren’t they??

###Here is the code:

At the beginning of my script I set CHUNKSIZE to 64 and define currentChunk as null.
GenerateWorld is called first.

public void GenerateWorld()
    {
        StartCoroutine("CreateChunks");
    }

Then it runs this function.

    IEnumerator CreateChunks()
    {
        chunks = new Tilemap[Mathf.CeilToInt(xCount / CHUNKSIZE), Mathf.CeilToInt(yCount / CHUNKSIZE)];
        for (int x = 0; x < xCount; x++)
        {

            for (int y = 0; y < yCount; y++)
            {
                if (x % CHUNKSIZE == 0 && y % CHUNKSIZE == 0)
                {
                    GameObject current = new GameObject();
                    current.transform.position = new Vector3Int(x, y, 0);
                    //Sets parent here and sets up Tilemaps components
                    chunks[x / CHUNKSIZE, y / CHUNKSIZE] = current.GetComponent<Tilemap>();

                    yield return null;
                }
            }
        }
        StartCoroutine("CreateCaves");
    }

Finally it runs this function.

    IEnumerator CreateCaves() {
        //float rand = Random.value;
        for (int x = 0; x < xCount; x++)
        {
            for (int y = 0; y < yCount; y++)
            {
                if ((int)x % CHUNKSIZE == 0 && (int)y % CHUNKSIZE == 0)
                {
                    currentChunk = chunks[(int)x / CHUNKSIZE, (int)y / CHUNKSIZE];
                    yield return null;
                }
                currentChunk.SetTile(new Vector3Int(x, y, 0), null);

                //if (Mathf.PerlinNoise(x / xCount * 100 + rand * 200000, y / yCount * 100 + rand * 200000) > 0.5F)
                //{
                //}
            }
        }
    }

You need to refresh the tile after setting it : currentChunk.RefreshTile(new Vector3Int(x, y, 0));