```\nuint256 currentThreshold = safe.getThreshold();\nuint256 newThreshold;\nuint256 target = targetThreshold; // save SLOADs\n\nif (validSignerCount <= target && validSignerCount != currentThreshold) {\n    newThreshold = validSignerCount;\n} else if (validSignerCount > target && currentThreshold < target) {\n    newThreshold = target;\n}\nif (newThreshold > 0) { // rest of code update safe threshold // rest of code }\n```\n