--- comment.module_original	2008-08-19 22:29:45.000000000 -0400
+++ comment.module	2008-08-19 22:30:08.000000000 -0400
@@ -738,13 +738,13 @@ function comment_save($edit) {
         if ($edit['pid'] == 0) {
           // This is a comment with no parent comment (depth 0): we start
           // by retrieving the maximum thread level.
-          $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
+          $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d and pid = 0', $edit['nid']));
 
           // Strip the "/" from the end of the thread.
           $max = rtrim($max, '/');
 
           // Finally, build the thread field for this new comment.
-          $thread = int2vancode(vancode2int($max) + 1) .'/';
+          $thread = int2vancode((int)vancode2int($max) + 1) .'/';
         }
         else {
           // This is comment with a parent comment: we increase
