Updated the castVote method to function