What was the main purpose of the Black Codes?

A. To allow black people to get married and to vote
B. To restrict freedom for black people
C. To protect black people from unfair laws
D. To provide sharecropping jobs