What was the purpose of Stalin's Great Terror?

A.to bring an end to the Russian civil war
B.to attack the German army during ww2
C.to eliminate unwanted ethnic groups from the USSR
D.to consolidate Stalin’s power and remove opposition