One idea to overcome this is: you work by small increments of features. You put each feature on the table and people bid the time to complete it. You assign the task to the one with the best reasonable estimate and with good track on the delivery - depending on the risk of failure. People that don't offer reasonable estimates can be replaced. The thing is that you know that without understanding the code, because someone else will bid less time and do it.
A variant is per-project, "last feature is free". After each feature, you pay the previous delivered feature, based on hourly time counted by the programmer. When you find the bill to be overcharged, you just pay the previous feature and close the collaboration. You might guaranty to pay a reasonable but fixed sum, in advance or at the end, to reduce the risk of the programmer to not be paid after too few tasks.
People should also have some stock or bonuses by global performance, otherwise they would not be also team players. And more than this, they should share a minimum motivation to be proud of the global outcome, for example because of how their work is making the world a bit better. Money if not always enough for people to really want to make it work.