refactoring grid, tricking matrix index instead of matrix value