Implement leadership elections.

Closes #100.