diff --git uuid.module uuid.module
index c2c6f48..e62662c 100644
--- uuid.module
+++ uuid.module
@@ -24,6 +24,17 @@ function uuid_menu() {
 
   return $items;
 }
+/**
+ * Load the uuid information for a node.
+ */
+function uuid_node_load($node) {
+  if ($arr = db_fetch_array(db_query('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', $node->vid, $node->nid))) {
+    return $arr;
+  }
+  else {
+   return array('uuid' => FALSE, 'revision_uuid' => FALSE);
+  }
+}
 
 /**
  * Implementation of hook_nodeapi().
@@ -33,12 +44,7 @@ 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,
-      );
+      return uuid_node_load($node);
     case 'insert':
       // Handle the case where automatic UUID generation is turned OFF but a
       // node is created, node_save(), intentionally with the $node->uuid
@@ -55,7 +61,7 @@ function uuid_nodeapi(&$node, $op, $teaser, $page) {
           db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
       }
-      elseif (in_array($node->type, $automatic_types)) {
+      elseif (in_array($node->type, $automatic_types, TRUE)) {
         $node->uuid = uuid_uuid();
         $node->revision_uuid = uuid_uuid();
         db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
@@ -63,12 +69,43 @@ 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);
+      // Get existing UUID info from the DB
+      $uuid_information = uuid_node_load($node);
+      $auto_create = in_array($node->type, $automatic_types, TRUE);
+      $uuid_exists = isset($node->uuid) && uuid_is_valid($node->uuid);
+      $uuid_in_db = !empty($uuid_information['uuid']);
+
+      // 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 ($uuid_exists || $auto_create) {
+        $node->uuid = $uuid_exists ? $node->uuid : uuid_uuid();
+        // Update the existing UUID.
+        if (!$uuid_in_db) {
+          db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
         }
-        else {
-          $node->revision_uuid = uuid_uuid();
+        elseif ($uuid_information['uuid'] != $node->uuid) {
+          db_query("UPDATE {uuid_node} SET uuid = '%s' WHERE nid = %d", $node->uuid, $node->nid);
+        }
+        $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;
+
+      // If a UUID exists, save a revision UUID if none exists or this is a new
+      // revision, or there's a programmatic revision set.
+      if ($uuid_exists && (empty($uuid_information['revision_uuid']) || !empty($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 = !empty($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);
         }
       }
diff --git uuid.test uuid.test
index 43fc231..4cba198 100644
--- uuid.test
+++ uuid.test
@@ -112,7 +112,7 @@ class UUIDUnitTestCase extends UUIDTestHelper {
    * Mark testcase as incomplete.
    */
   function testMarkIncomplete() {
-    $this->markIncomplete(t("This test in incomplete."));
+    $this->markIncomplete(t("This test is incomplete."));
   }
 
 
@@ -154,14 +154,14 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     $object = $this->drupalCreateNode($options);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with default settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with default settings."),
       t("Node revision UUID")
     );
 
@@ -170,14 +170,14 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     node_save($object);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with default settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with default settings."),
       t("Node revision UUID")
     );
 
@@ -193,9 +193,9 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     $object = $this->drupalCreateUser();
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("User has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("User has no uuid field attached with default settings."),
       t("User UUID")
     );
   }
@@ -240,14 +240,14 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     $object = $this->drupalCreateNode($options);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with disabled settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with disabled settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with disabled settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with disabled settings."),
       t("Node revision UUID")
     );
 
@@ -256,17 +256,53 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     node_save($object);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with default settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with default settings."),
       t("Node revision UUID")
     );
 
+    // Test Programmatically setting UUIDs.
+    $new_uuid = uuid_uuid();
+    $revision_uuid = uuid_uuid();
+    $options = array(
+      'uid'  => $account->uid,
+      'type' => 'page',
+      'uuid' => $new_uuid,
+      'revision_uuid' => $revision_uuid,
+    );
+    $object = $this->drupalCreateNode($options);
+    $loaded_node = node_load($object->nid, NULL, TRUE);
+
+    $this->assertEqual(
+      $object->uuid,
+      $new_uuid,
+      t("Node uuid can be set programmatically with disabled settings."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->uuid,
+      $loaded_node->uuid,
+      t("Node uuid is being returned correctly."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $revision_uuid,
+      t("Node revision uuid can be set programmatically with disabled settings."),
+      t("Node Revision UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $loaded_node->revision_uuid,
+      t("Node revision uuid is being returned correctly."),
+      t("Node Revision UUID")
+    );
   }
 
   /**
@@ -283,9 +319,9 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     $object = $this->drupalCreateUser();
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("User has not uuid field attached with disabled settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("User has no uuid field attached with disabled settings."),
       t("User UUID")
     );
   }
@@ -306,7 +342,11 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
 
   /**
    * Verify uuid behavior with enabled settings. All settings are forced to
-   * enabled, so new 'entities' should get an uuid assigned.
+   * enabled, so new 'entities' should get a uuid assigned.
+   *
+   * Note that there have been issues with the uuid values the node object
+   * after saving not necessarily reflecting what's in the database, so check
+   * with a node_load().
    */
 
   /**
@@ -344,12 +384,45 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     // Show current node only in verbose mode.
     $this->verbose(print_r($object, 1));
 
+    // Test saving without a new revision
+    $uuid = $object->uuid;
+    $revision_uuid = $object->revision_uuid;
+    $object->revision = FALSE;
+    node_save($object);
+    $loaded_object = node_load($object->nid, NULL, TRUE);
+
+    $this->assertEqual(
+      $object->uuid,
+      $uuid,
+      t("Node uuid is preserved after update with revisioning off."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $loaded_object->uuid,
+      $uuid,
+      t("Node uuid loads correctly after update with revisioning off."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $revision_uuid,
+      t("Node revision uuid is preserved after update with revisioning off."),
+      t("Node Revision UUID")
+    );
+    $this->assertEqual(
+      $loaded_object->revision_uuid,
+      $revision_uuid,
+      t("Node revision uuid loads correctly after update with revisioning off."),
+      t("Node Revision UUID")
+    );
+
     // make a copy of this node.
     $node = clone($object);
 
     // Create a new revision for this node.
     $object->revision = 1;
     node_save($object);
+    $loaded_node = node_load($object->nid, NULL, TRUE);
 
     // Verify fields are attached to the node.
     $this->assertIsUUID(
@@ -371,12 +444,58 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
       t("Node UUID")
     );
     $this->assertNotEqual(
-      $object->uuid,
-      $node->uuid,
+      $object->revision_uuid,
+      $node->revision_uuid,
       t("Node revision uuid is being updated successfully."),
       t("Node revision UUID")
     );
 
+    // Verify altered object reflects what's really in the database
+    $this->assertEqual(
+      $object->uuid,
+      $loaded_node->uuid,
+      t("Node uuid is being returned correctly."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $loaded_node->revision_uuid,
+      t("Node revision uuid is being returned correctly."),
+      t("Node revision UUID")
+    );
+
+    // Replace the UUID
+    $new_uuid = uuid_uuid();
+    $revision_uuid = uuid_uuid();
+    $object->uuid = $new_uuid;
+    $object->revision_uuid = $revision_uuid;
+    node_save($object);
+    $loaded_node = node_load($object->nid, NULL, TRUE);
+    $this->assertEqual(
+      $object->uuid,
+      $new_uuid,
+      t("Node uuid is being changed correctly."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->uuid,
+      $loaded_node->uuid,
+      t("Node uuid is being returned correctly."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $revision_uuid,
+      t("Node revision uuid is being changed correctly."),
+      t("Node Revision UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $loaded_node->revision_uuid,
+      t("Node revision uuid is being returned correctly."),
+      t("Node Revision UUID")
+    );
+
     // Show current node only in verbose mode.
     $this->verbose(print_r($node, 1));
   }
@@ -416,6 +535,88 @@ class UUIDFunctionalityTestCase extends UUIDTestHelper {
     $this->markIncomplete(t("This test is incomplete."));
   }
 
+  /**
+   * Verify uuid behavior with changed settings. All settings are forced to
+   * disabled, then a node is created (with no UUID). Then settings are enabled,
+   * and the node is resaved, which should trigger UUIDs being created.
+   */
+  function testChangedSettingNodeUUID() {
+    // Set module settings.
+    $settings = array(
+      'uuid_automatic_for_nodes[page]'  => FALSE,
+    );
+    $this->uuidSettingsSet($settings);
+
+    // Create a user.
+    $account = $this->drupalCreateUser(array('create page content'));
+
+    // Create a node with that user.
+    $options = array(
+      'uid'  => $account->uid,
+      'type' => 'page',
+    );
+    $object1 = $this->drupalCreateNode($options);
+    $object2 = $this->drupalCreateNode($options);
+
+    // Set module settings.
+    $settings = array(
+      'uuid_automatic_for_nodes[page]' => TRUE,
+    );
+    $this->uuidSettingsSet($settings);
+
+    node_save($object1);
+
+    // Verify fields are attached to the node.
+    $this->assertIsUUID(
+      $object1->uuid,
+      t("Node has uuid field attached with previously disabled settings."),
+      t("Node UUID")
+    );
+    $this->assertIsUUID(
+      $object1->revision_uuid,
+      t("Node has revision uuid field attached with previously disabled settings."),
+      t("Node revision UUID")
+    );
+
+    // Show current node only in verbose mode.
+    $this->verbose(print_r($object1, 1));
+
+    // Now programmatically set UUIDs and test with object2
+    $new_uuid = uuid_uuid();
+    $revision_uuid = uuid_uuid();
+    $object2->uuid = $new_uuid;
+    $object2->revision_uuid = $revision_uuid;
+    node_save($object2);
+    $loaded_node = node_load($object2->nid, NULL, TRUE);
+    $this->assertEqual(
+      $object2->uuid,
+      $new_uuid,
+      t("Node uuid can be set programmatically with changed settings."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object2->uuid,
+      $loaded_node->uuid,
+      t("Node uuid with changed settings is being returned correctly."),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object2->revision_uuid,
+      $revision_uuid,
+      t("Node revision uuid can be set programmatically with changed settings."),
+      t("Node Revision UUID")
+    );
+    $this->assertEqual(
+      $object2->revision_uuid,
+      $loaded_node->revision_uuid,
+      t("Node revision uuid with changed settings is being returned correctly."),
+      t("Node Revision UUID")
+    );
+
+    // Show current node only in verbose mode.
+    $this->verbose(print_r($object2, 1));
+  }
+
 }
 
 
