you don't need a loop and an if-condition here.

I assume you can just use the following?
```
grid_domain.appendChild(main_grid)
poly_domain.appendChild(main_poly)
```