--- coherent_access.module	2008-11-03 12:39:40.000000000 -0600
+++ coherent_access.module.fixed	2009-01-22 19:09:37.000000000 -0600
@@ -410,17 +410,18 @@ function coherent_access_nodeapi(&$node,
         $gids = coherent_access_get_gids($node->nid);
         
         // obtain the private status of our node
-        $result = db_query('SELECT count(*) FROM {node_access} WHERE realm = "%s" AND gid = %d', 'coherent_access', $gids[0]);
-        $rows = db_result($result); // FIX: review this change from db_num_rows to ensure it is appropriate 
-        if ($rows > 0) {
+        // first, see if their are entries for the node in the node_access table
+        $result = db_query('SELECT count(*) FROM {node_access} WHERE realm = "%s" AND nid = %d', 'coherent_access', $node->nid);
+        $rows = db_result($result);
+        if ($rows > 0) {  // node exists in node_access, determine if grant_view ...
           $result = db_query('SELECT grant_view FROM {node_access} WHERE realm = "%s" AND gid = %d', 'coherent_access', $gids[0]);
-          $private = (db_result($result) ? 0 : 1);
+          $private = (db_result($result) ? 0 : 1);  //  if there are no gid = $gids[0] rows, it must be private
         }
         else {
-          // we don't have an entry in node_access... load a predefined default setting
-          $private = variable_get('coherent_access_default_node_private', 0);  // load default node visibility settings
+          // we don't have an entry for this nid in node_access, so load a predefined default setting for the new node
+          $private = variable_get('coherent_access_default_node_private', 0);
         }
-        
+
         $node->coherent_access['private'] = $grant_view;
         
         $result = db_query('SELECT u.uid, u.name FROM {users} u LEFT JOIN {coherent_access_user} ca ON ca.uid = u.uid WHERE ca.gid = %d', $gids[COHERENT_ACCESS_VIEW | COHERENT_ACCESS_EDIT]);
