Implement MasterElection

Also, separate suggestion: Make this an ```enum class``` (or is it ```class enum```)? This adds a bit more static checking, as I recall, and adds scoping (which might be a bit annoying, you might want to rename this to something shorter, like just ```State```).