Why has Museveni survived so long in spite of serious flaws?

A while back I talked with some people who are familiar with Uganda’s political economy situation. We touched, inter alia, on the dangerously deteriorating social and environmental conditions in urban and rural areas which under normal circumstances would have created serious problems for Museveni in cabinet, parliament and the general population. Yet Museveni keeps on getting nominated for re-election. In true democratic terms where the public freely and fairly chooses the party candidate, one participant observed, Museveni would possibly not be re-nominated, much less re-elected. He has managed to stay in power by purchasing loyalty of the Uganda elites in the military and administration, and by aligning himself with western interests in economic, political and security areas.