Fix misallocation of grid ids