refactoring. testing on a 512 grid.