Use scanl and scanr to update the grid
More refactoring
Remove whitespace