refactored the voting function a little