refactor of grid