improovement and refactoring on the grid