How did Stalin manage to assume control over Russia in the five years following the death of Lenin in 1924?

How did Stalin manage to assume control over Russia in the five years following the death of Lenin in 1924?
In 1924 Russia was in a very delicate state. Recovering from an economy in ruins, it was being rebuilt slowly by the NEP (New Economic Policy) the country was gradually growing in wealth with larger industries and factories being returned to their owners, traders were now allowed to buy and sell their goods (this was illegal during war communism) and grain requisitioning was stopped, this meant no grain could be taken from the peasants by force. People were changing as well, the idea of equality was introduced, religion was almost abolished, forbidding anyone under 15 years old to learn about it with churches taken over and priests exiled. Schools were being built and people were beginning to be fed a lot more than in earlier years, where Russians had been starving to death on the streets.
When Lenin died in 1924 aged 53 of several strokes he had had since 1922, this caused a power struggle. There were several men in the running for his replacement. The first of these men was Stalin, the General Secretary of Russia, his opinions were centred and inoffensive to either side of the party, he also could appoint and dismiss members whenever he wanted to giving him opportunity to eliminate his enemies and bring in more supporters. Another candidate, Trotsky, was an excellent revolutionary ideas and had led the Red Army to victory in the Civil War. There was also Kamenev and Zinoviev who both had local power bases in Leningrad and Moscow, which were key cities for the Bolsheviks, both them and Trotsky wanted rapid industrialisation organised by the state. Finally there was Bukharin, who was extremely popular among the younger members of the party and had a reputation as a very skilled theorist, he wanted to continue with the NEP and move slowly towards communism.
In 1924 Russia was in a very delicate state. Recovering from an economy in ruins, it was being rebuilt slowly by the NEP (New Economic Policy) the country was gradually growing in wealth with larger industries and factories being returned to their owners, traders were now allowed to buy and sell their goods (this was illegal during war communism) and grain requisitioning was stopped, this meant no grain could be taken from the peasants by force. People were changing as well, the idea of equality was introduced, religion was almost abolished, forbidding anyone under 15 years old to learn about it with churches taken over and priests exiled. Schools were being built and people were beginning to be fed a lot more than in earlier years, where Russians had been starving to death on the streets.
When Lenin died in 1924 aged 53 of several strokes he had had since 1922, this caused a power struggle. There were several men in the running for his replacement. The first of these men was Stalin, the General Secretary of Russia, his opinions were centred and inoffensive to either side of the party, he also could appoint and dismiss members whenever he wanted to giving him opportunity to eliminate his enemies and bring in more supporters. Another candidate, Trotsky, was an excellent revolutionary ideas and had led the Red Army to victory in the Civil War. There was also Kamenev and Zinoviev who both had local power bases in Leningrad and Moscow, which were key cities for the Bolsheviks, both them and Trotsky wanted rapid industrialisation organised by the state. Finally there was Bukharin, who was extremely popular among the younger members of the party and had a reputation as a very skilled theorist, he wanted to continue with the NEP and move slowly towards communism.
