implemented subgrid and cartesian product