Refactor voting code