refactoring the grid