diff --git uuid.module uuid.module
index e47207c..344dd0b 100644
--- uuid.module
+++ uuid.module
@@ -33,12 +33,13 @@ function uuid_nodeapi(&$node, $op, $teaser, $page) {
 
   switch ($op) {
     case 'load':
-      $revision_uuid = db_result(db_query('SELECT uuid FROM {uuid_node_revisions} WHERE vid = %d', $node->vid));
-      return array(
-        'uuid' => db_result(db_query('SELECT uuid FROM {uuid_node} WHERE nid = %d', $node->nid)),
-        'revision_uuid' => $revision_uuid,
-        'loaded_revision_uuid' => $revision_uuid,
-      );
+      $sql = "SELECT un.uuid AS uuid, unr.uuid AS revision_uuid
+              FROM {uuid_node} un
+              LEFT JOIN {uuid_node_revisions} unr ON unr.vid = %d WHERE un.nid = %d";
+      if ($record = db_fetch_array(db_query($sql, $node->vid, $node->nid))) {
+        return $record;
+      }
+      break;
     case 'insert':
       // Handle the case where automatic UUID generation is turned OFF but a
       // node is created, node_save(), intentionally with the $node->uuid
@@ -63,12 +64,38 @@ function uuid_nodeapi(&$node, $op, $teaser, $page) {
       }
       break;
     case 'update':
-      if (isset($node->revision)) {
-        if (isset($node->revision_uuid) && uuid_is_valid($node->revision_uuid) && $node->revision_uuid != $node->loaded_revision_uuid) {
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
-        }
-        else {
-          $node->revision_uuid = uuid_uuid();
+      $auto_create = in_array($node->type, $automatic_types);
+
+      $uuid_exists = isset($node->uuid) && uuid_is_valid($node->uuid);
+      $uuid_in_db = db_result(db_query('SELECT 1 FROM {uuid_node} WHERE nid = %d', $node->nid));
+      $uuid_needs_saved = $uuid_exists && !$uuid_in_db;
+
+      // Create a UUID if this is an automatic type but no UUID exists. Save the
+      // UUID if it's valid but is not in the database.
+      if (($auto_create && !$uuid_exists) || $uuid_needs_saved) {
+        $node->uuid = $uuid_exists ? $node->uuid : uuid_uuid();
+        db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
+        $uuid_exists = TRUE;
+      }
+
+      $rev_uuid_exists = isset($node->revision_uuid) && uuid_is_valid($node->revision_uuid);
+      $rev_uuid_in_db = $rev_uuid_exists ? db_result(db_query("SELECT 1 FROM {uuid_node_revisions} WHERE uuid = '%s'", $node->revision_uuid)) : FALSE;
+      $rev_uuid_needs_saved = $rev_uuid_exists && !$rev_uuid_in_db;
+
+      // Save a revision UUID if none exists, or if this is a new revision, or
+      // if a revision_uuid exists, but not yet in the database. This code is
+      // only applicable if a valid node UUID exists, so we check that first.
+      if ($uuid_exists && (!$rev_uuid_exists || isset($node->revision) || $rev_uuid_needs_saved)) {
+        // We need to determine when to generate a new revision UUID. This
+        // should only happen if this is a new revision and if the existing
+        // revision uuid already exists in the database or doesn't exist at all.
+        $generate_new = isset($node->revision) && ($rev_uuid_in_db || !$rev_uuid_exists);
+        $node->revision_uuid = $generate_new ? uuid_uuid() : $node->revision_uuid;
+
+        // Be sure to consider the case where the revision_uuid may be changing
+        // programmatically, so try updating first.
+        db_query("UPDATE {uuid_node_revisions} SET uuid = '%s' WHERE vid = %d", $node->revision_uuid, $node->vid);
+        if (!db_affected_rows()) {
           db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
       }
