diff --git a/bestreply.module b/bestreply.module
index d900528..cd8e9ff 100644
--- a/bestreply.module
+++ b/bestreply.module
@@ -135,63 +135,63 @@ function bestreply_comment(&$comment, $op) {
 /**
  * Implementation of hook_link().
  */
-function bestreply_link($type, $node = NULL, $teaser = FALSE) {
+function bestreply_link($type, $object = NULL, $teaser = FALSE) {
   $brname = variable_get('bestreply_name', 'bestreply');
 
-  if (!isset($node)) {
+  if (!isset($object)) {
     return;
   }
   global $user;
-  $nts=variable_get('bestreply_types', array());
+  $nts = variable_get('bestreply_types', array());
   switch ($type) {
     case 'comment':
-      $ntype= bestreply_parent_type($node->nid);
+      // $object is a comment object
+      $ntype = bestreply_parent_type($object->nid);
       if (!isset($nts[$ntype]) || $nts[$ntype] == '0' ) {
         return;
       }
-       //if logged in and not the comment author
-      if ($user->uid && $user->uid != $node->uid) {
-        $nuid = db_result(db_query("SELECT uid from {node} where nid = %d", $node->nid));
-        $author = (($user->uid == $nuid));
-        $moderator = user_access('moderate bestreply');
-        $brcid = bestreply_ismarked($node->nid);
-        if (!$brcid) {
-          if ($author && user_access('mark bestreply') || $moderator) {
+      
+      // Determine the node this comment belongs to
+      $nuid = db_result(db_query("SELECT uid from {node} where nid = %d", $object->nid));
+      $author = (($user->uid == $nuid));
+      $moderator = user_access('moderate bestreply');
+      $brcid = bestreply_ismarked($object->nid);
+      if (!$brcid) {
+        if ($author && user_access('mark bestreply') || $moderator) {
+          $links['bestreply_link'] = array(
+          'title' =>  $brname,
+          'href' => 'bestreply/mark/'. $object->cid,
+          'attributes' => array('title' => t('Mark this comment as the !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_mark'),
+          );
+        }
+      }
+      else{
+        if ($brcid == $object->cid) {
+          if ($author && user_access('clear bestreply') || $moderator) {
             $links['bestreply_link'] = array(
-            'title' =>  $brname,
-            'href' => 'bestreply/mark/'. $node->cid,
-            'attributes' => array('title' => t('Mark this comment as the !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_mark'),
+            'title' => t('Clear !bestreply', array('!bestreply' => $brname)),
+            'href' => 'bestreply/clear/'. $object->cid,
+            'attributes' => array('title' => t('Clear this !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_clear'),
             );
           }
         }
         else{
-          if ($brcid == $node->cid) {
-            if ($author && user_access('clear bestreply') || $moderator) {
-              $links['bestreply_link'] = array(
-              'title' => t('Clear !bestreply', array('!bestreply' => $brname)),
-              'href' => 'bestreply/clear/'. $node->cid,
-              'attributes' => array('title' => t('Clear this !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_clear'),
-              );
-            }
-          }
-          else{
-            if ($author && user_access('mark bestreply') || $moderator) {
-              $links['bestreply_link'] = array(
-              'title' =>  $brname,
-              'href' => 'bestreply/mark/'. $node->cid,
-              'attributes' => array('title' => t('Set this comment as the !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_mark'),
-              );
-            }
+          if ($author && user_access('mark bestreply') || $moderator) {
+            $links['bestreply_link'] = array(
+            'title' =>  $brname,
+            'href' => 'bestreply/mark/'. $object->cid,
+            'attributes' => array('title' => t('Set this comment as the !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_mark'),
+            );
           }
         }
       }
     break;
     case 'node':
-      if (!isset($nts[$node->type]) || $nts[$node->type] == '0') {
+      if (!isset($nts[$object->type]) || $nts[$object->type] == '0') {
         return;
       }
       drupal_add_js(drupal_get_path('module', 'bestreply') .'/bestreply.js');
-      $brid = bestreply_ismarked($node->nid);
+      $brid = bestreply_ismarked($object->nid);
       $movetotop= variable_get('bestreply_movetotop', 'yes');
       $collapse= variable_get('bestreply_collapse', '');
 
@@ -205,7 +205,7 @@ function bestreply_link($type, $node = NULL, $teaser = FALSE) {
       if ($brid && user_access('view bestreply')) {
         $links['bestreply_view'] = array(
           'title' => t('view !bestreply', array('!bestreply' => $brname)),
-          'href' => 'node/'. $node->nid,
+          'href' => 'node/'. $object->nid,
           'fragment' => 'comment-'. $brid,
           'attributes' => array('title' => t('Jump to the !bestreply.', array('!bestreply' => $brname)), 'class' => 'br_view'),
         );
@@ -217,7 +217,6 @@ function bestreply_link($type, $node = NULL, $teaser = FALSE) {
   }
 }
 
-
 /**
  * Insert or update the marked comment info.
  */
