Why did GDR build a wall through Berlin?

In the twelve years after the founding of the GDR, about 2.5 million people fled the country and went to the FRG. They wanted better living conditions and freedom of opinion because the GDR did not allow any political views that were against the government. To prevent this mass migration of people to the West, the GDR built a wall around West Berlin in August 1961. Moreover, it also renovated the 1800 km long border fence to the FRG with spring guns and made it a ‘death strip’.