refactoring to turn the grid into an immutable object