Refactor election code.