It's impossible to program what is inherently broken unless of course your software was full of glitches and had as many bugs in it as our governments. You can of course debug, but the glitches are impossible to predict, and thus program.
If you were to remove all elected officials from the equation, then programming becomes a much more straightforward task and could be done following due process. In an ideal world passing laws/policies would be a matter of logic, where the benefit of citizens and planet are the primary objectives. However, given the interests and persuasions of individual players, and the influences of third parties, even the deepest of phycological and analytical appraisal tools would come up short when trying to predict the decisions of any given policymaker.
Maybe that's the way to tackle this, remove the protagonists and concentrate on the system. Once you have a schema of the system, you could attempt to integrate the variables. Good luck with the latter.
IMO, I would start again. Determine where the power is now, and think about where it should be. How the decisions are made now and how they could be made better with your system.
You may already know about it but if not, this might give you some inspiration: https://www.globalchallenges.org/en
In essence, there is a 5m prize pool for someone/team to come up with a UN 2.0. One that works. That would entail fixing governments for any kind of UN to work effectively.