What was the main purpose of the Black Codes?

A: To bring an end to reconstruction
B: To preserve white supremacy
C: To return the Democratic party to power
D: Prevent blacks from leaving the south