Final version. Implemented an array to store the grid.