refactored grid dimensions computation