refactoring 2dgrid