easy general and modular C++ code | clean and understandable
\nclass Solution {\npublic:\n    vector<vector<int>>  regionSum, regionCount;\n    int limit = 3;\n    int thres;\n    bool handler(int i, int j, vector<vector<
```\nclass Solution {\npublic:\n    vector<vector<int>>  regionSum, regionCount;\n    int limit = 3;\n    int thres;\n    bool handler(int i, int j, vector<vector<int>>&image) {\n        bool check = true;\n\n        for (int k = 0; k < limit ; k++) {\n            for (int l = 1; l < limit ; l++) {\n                if (abs(image[i + k][j + l] - image[i + k][j + l - 1]) > thres) {\n                    check = false;\n                }\n            }\n        }\n\n        for (int k = 1; k < limit; k++) {\n            for (int l = 0; l < limit ; l++) {\n                if (abs(image[i + k][j + l] - image[i + k - 1][j + l]) > thres) {\n                    check = false;\n                }\n            }\n        }\n\n        return check;\n    }\n    void sumAndUpdate(int i, int j, vector<vector<int>>&image) {\n        int sum = 0;\n        for (int k = 0; k < limit ; k++) {\n            for (int l = 0; l < limit ; l++) {\n                sum += image[i + k][j + l];\n            }\n        }\n        for (int k = 0; k < limit ; k++) {\n            for (int l = 0; l < limit; l++) {\n\n                regionCount[i + k][j + l]++;\n                regionSum[i + k][j + l] = (regionSum[i + k][j + l] + sum / 9);\n            }\n        }\n    }\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        int n = image.size();\n        int m = image[0].size();\n        thres = threshold;\n        regionSum.resize(n, vector<int>(m, 0));\n        regionCount.resize(n, vector<int>(m, 0));\n\n        for (int i = 0; i <= n - limit; i++) {\n            for (int j = 0; j <= m - limit; j++) {\n\n                if (handler(i, j, image)) {\n                    sumAndUpdate(i, j, image);\n                }\n            }\n        }\n\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (regionCount[i][j] == 0)\n                    regionSum[i][j] = image[i][j];\n\n                else\n                    regionSum[i][j] = (regionSum[i][j]) / regionCount[i][j];\n            }\n        }\n\n        return regionSum;\n    }\n};\n\n```
[]