refactored subdivideGrid()