started refactoring grid code