--- fivestar.module	2008-02-23 18:04:10.000000000 -0800
+++ fivestarNew.module	2008-02-23 18:03:09.000000000 -0800
@@ -590,50 +590,36 @@ function _fivestar_cast_vote($type, $cid
     if ($value > 100) {
       $value = 100;
     }
-
-    // If the vote value is 0, blindly nuke any votes for this content by the user.
-    if ($value == 0) {
-      if ($uid) {
-        // If the user is logged in, we'll delete votes from that uid.
-        $sql = "DELETE FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag='%s'";
-        db_query($sql, $type, $cid, $uid, $tag);
-        return votingapi_recalculate_results($type, $cid);
-      }
-      else {
-        // Otherwise, we'll delete votes from the same IP address within the anonymous interval.
-        $sql = "DELETE FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag='%s' AND hostname='%s'";
-        $sql .= $anon_interval != -1 ? " AND timestamp > %d" : '';
-        db_query($sql, $type, $cid, $uid, $tag, $hostname, time() - $anon_interval);
-        return votingapi_recalculate_results($type, $cid);
-      }
-    }
-    // If the vote ISN'T zero, check for existing votes in the database.
+		
+    if ($uid) {
+      // If the user is logged in, we'll look for votes from that uid.
+      $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag = '%s'";
+      $result = db_query($sql, $type, $cid, $uid, $tag);
+    } 
     else {
-      if ($uid) {
-        // If the user is logged in, we'll look for votes from that uid.
-        $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag = '%s'";
-        $result = db_query($sql, $type, $cid, $uid, $tag);
-      }
-      else {
-        // Otherwise, we'll look for votes from the same IP address within the anonymous interval.
-        $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag = '%s' AND hostname='%s'";
-        $sql .= $anon_interval != -1 ? " AND timestamp > %d" : '';
-        $result = db_query($sql, $type, $cid, $uid, $tag, $hostname, time() - $anon_interval);
-      }
-    }
+      // Otherwise, we'll look for votes from the same IP address within the anonymous interval.
+      $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag = '%s' AND hostname='%s'";
+      $sql .= $anon_interval != -1 ? " AND timestamp > %d" : '';
+      $result = db_query($sql, $type, $cid, $uid, $tag, $hostname, time() - $anon_interval);
+		}
 
     // If the old vote exists, either delete it (if the new one is zero)
     // or change it. If it doesn't exist and the vote is non-zero, cast
-    // it and recalculate.
+    // it and recalculate.		
     if ($old_vote = db_fetch_object($result)) {
-      votingapi_change_vote($old_vote, $value);
-    }
+      if ($value == 0){
+        votingapi_delete_vote($old_vote);
+			} 
+			else {
+        votingapi_change_vote($old_vote, $value);
+			}
+    } 
     elseif ($value != 0) {
-      votingapi_add_vote($type, $cid, $value, 'percent', $tag, $uid);
+			votingapi_add_vote($type, $cid, $value, 'percent', $tag, $uid);
     }
     return votingapi_recalculate_results($type, $cid);
-  }
-  else {
+  } 
+	else {
     return array();
   }
 }
