How to delete rows in a flood fill game

Hi i want to delete rows that get filled by one color in a flood fill game. The problem is that when i delete a row it gives me the null object reference error. the error occurs since the node in floodFill method is the first tile on the grid.
here is an image to show you which rows i mean to delete66698-capture.png

Can anyone advise me any way to do this. I do not necessarily need code but a way to do it.
here is my floodfill code

public void floodFill (Color replacementColor)
	{
		Color targetColor = node.GetComponent<SpriteRenderer>().color;

		if (node.GetComponent<SpriteRenderer> ().color != targetColor)
			return;

		if (node.GetComponent<SpriteRenderer> ().color == replacementColor)
			return;

		Q.Enqueue (node);

		while (Q.Count > 0) {
			
			 n = Q.Dequeue (); 
			Debug.Log ("n" + n.transform.position);
	

			if (FindColorOfGameObjectFromPos (new Vector2 (n.transform.position.x, n.transform.position.y)) == targetColor) {

				int w = (int)n.transform.position.x;
				int e = (int)n.transform.position.x;
				int y = (int)n.transform.position.y;


				while ((w > 0) && FindColorOfGameObjectFromPos (new Vector2 (w - 1, y)) == targetColor) {
					w--;	 
				}

				while (((e < 17) && FindColorOfGameObjectFromPos (new Vector2 (e + 1, y)) == targetColor)) {
					e++;
				}

				for (int i = w; i <= e; i++) {
					
					FindGameObjectFromPos (new Vector3 (i, y)).GetComponent<SpriteRenderer>().color = replacementColor;

					if ((y > 0)) {
						if (FindColorOfGameObjectFromPos (new Vector2 (i, y - 1)) == targetColor) {
							Q.Enqueue (FindGameObjectFromPos (new Vector2 (i, y - 1)));

						}
					}

					if ((y < rows - 1)) {
						if (FindColorOfGameObjectFromPos (new Vector2 (i, y + 1)) == targetColor) {
							
							Q.Enqueue (FindGameObjectFromPos (new Vector2 (i, y + 1)));
		
						}
					}
				}
					
				player.position = new Vector2 (e, y);
			}
		}
	}

@Bunny83

Hi,
I think you may be able to do something easier by assigning an ID to your tiles in function of the color when your script generates a color it also assign the ID to the script on the tile.
Then adding a row manager game object. Your tiles will become children of the row manager and the row manager will cycle through all its children and check their ID and if all IDs are the same it will delete itself and the children.
If you don’t want to put a script on each tile for the ID - you could put an array on the row manager - an array of IDs of colors which you would update and cycle through that array - if all are equal - delete the row manager and children.
what do you think?
hope it helps