Updated grid[XYToIndex