code refactoring in grid