diff --recursive -u ./site_verify.admin.inc ./site_verify.admin.inc
--- ./site_verify.admin.inc	2011-02-20 23:37:54.000000000 +0100
+++ ./site_verify.admin.inc	2011-02-08 23:30:23.212203848 +0100
@@ -1,6 +1,9 @@
 <?php
 // $Id: site_verify.admin.inc,v 1.21 2011/02/20 22:37:54 davereid Exp $
 
+/**
+ * Page callback to show a list of site-verification records.
+ */
 function site_verify_list() {
   $engines = site_verify_get_engines();
   $destination = drupal_get_destination();
@@ -55,8 +58,15 @@
   return $build;
 }
 
+/**
+ * Form to add/edit a verification record.
+ *
+ * Step 1: Choose ENGINE (Bing, Google, etc).
+ * Step 2: Enter verification details (meta-tag or verification file).
+ */
 function site_verify_edit_form($form, &$form_state, $record = array(), $engine = NULL) {
   if (!isset($form_state['storage']['step'])) {
+    // Add default placeholders.
     $record += array(
       'svid' => NULL,
       'file' => '',
@@ -75,6 +85,7 @@
 
   switch ($form_state['storage']['step']) {
     case 1:
+      // Build  list of possible verification engines.
       $engines = site_verify_get_engines();
       $options = array();
       foreach ($engines as $key => $engine) {
@@ -92,8 +103,8 @@
         '#value' => t('Next'),
       );
       break;
-    case 2:
 
+    case 2:
       $form['svid'] = array(
         '#type' => 'value',
         '#value' => $record['svid'],
@@ -105,8 +116,9 @@
       $form['engine_name'] = array(
         '#type' => 'item',
         '#title' => t('Search engine'),
-        '#value' => $record['engine']['name'],
+        '#markup' => $record['engine']['name'],
       );
+
       $form['#engine'] = $record['engine'];
 
       $form['meta'] = array(
@@ -141,6 +153,7 @@
         '#wysiwyg' => FALSE,
         '#access' => $record['engine']['file_contents'],
       );
+      // Add a warning message if Clean URLs is not available.
       if (!variable_get('clean_url', 0)) {
         drupal_set_message(t('Using verification files will not work if <a href="@clean-urls">clean URLs</a> are disabled.', array('@clean-urls' => url('admin/settings/clean-url'))), 'error', FALSE);
         $form['file']['#disabled'] = TRUE;
@@ -192,6 +205,8 @@
     }
   }
 
+  // Confirm that the desired filename isn't already in use by another
+  // verification.
   if ($values['file']) {
     $existing_file = db_query("SELECT svid FROM {site_verify} WHERE LOWER(file) = LOWER(:file) AND svid <> :svid", array(':file' => $values['file'], 'svid' => $values['svid']))->fetchField();
     if ($existing_file) {
@@ -211,25 +226,21 @@
     $form_state['rebuild'] = TRUE;
   }
   else {
-    // Save the verification to the database.
-    if ($form_state['values']['svid']) {
-      drupal_write_record('site_verify', $form_state['values'], array('svid'));
-    }
-    else {
-      drupal_write_record('site_verify', $form_state['values']);
+    $record = (object) $form_state['values'];
+    if (empty($record->file)) {
+      $record->file_contents = '';
     }
+    site_verify_save($record);
 
     drupal_set_message(t('Verification saved.'));
     $form_state['storage'] = $form_state['rebuild'] = NULL;
     $form_state['redirect'] = 'admin/config/search/verifications';
-
-    // Clear front page caches and set the menu to be rebuilt.
-    cache_clear_all(url('<front>', array('absolute' => TRUE)), 'cache_page');
-    cache_clear_all(url(variable_get('site_frontpage', 'node'), array('absolute' => TRUE)), 'cache_page');
-    variable_set('menu_rebuild_needed', TRUE);
   }
 }
 
+/**
+ * Delete form: found at admin/config/search/verifications/xxx/delete
+ */
 function site_verify_delete_form($form, $form_state, $record) {
   $form['record'] = array(
     '#type' => 'value',
@@ -248,17 +259,16 @@
 
 function site_verify_delete_form_submit($form, &$form_state) {
   $record = $form_state['values']['record'];
-  db_delete('site_verify')->condition('svid', $record['svid'])->execute();
+  site_verify_delete($record['svid']);
+
   drupal_set_message(t('Verification for %engine has been deleted.', array('%engine' => $record['engine']['name'])));
-  watchdog('site_verify', 'Verification for %engine deleted.', array('%engine' => $record['engine']['name']), WATCHDOG_NOTICE);
   $form_state['redirect'] = 'admin/config/search/verifications';
-
-  // Clear front page caches and set the menu to be rebuilt.
-  cache_clear_all(url('<front>', array('absolute' => TRUE)), 'cache_page');
-  cache_clear_all(url(variable_get('site_frontpage', 'node'), array('absolute' => TRUE)), 'cache_page');
-  variable_set('menu_rebuild_needed', TRUE);
 }
 
+
+/**
+ * Validate that the 'meta' property uses the correct pattern for Google.
+ */
 function site_verify_validate_meta_google($element, &$form_state) {
   $value = strtolower(trim($element['#value']));
   if ($value != '' && !preg_match('%\A<meta name="verify-v1" content="[\S]+" />\Z%', $value)) {
@@ -266,6 +276,7 @@
   }
 }
 
+
 function site_verify_validate_page_google($element, &$form_state) {
   $value = strtolower(trim($element['#value']));
   if ($value != '' && !preg_match('%\Agoogle[\da-f]+\.html\Z%', $value)) {
Only in ./: ._site_verify.module
diff --recursive -u ./site_verify.module ./site_verify.module
--- ./site_verify.module	2011-02-20 23:37:54.000000000 +0100
+++ ./site_verify.module	2011-02-08 23:31:54.444201390 +0100
@@ -2,9 +2,17 @@
 // $Id: site_verify.module,v 1.17 2011/02/20 22:37:54 davereid Exp $
 
 /**
+ * @file
+ * Site Verify provides a tool for verification codes (meta tags or custom
+ * pages) to be added to the site, for verification with external search
+ * engines.
+ */
+
+/**
  * Implements hook_menu().
  */
 function site_verify_menu() {
+  // List all verification records.
   $items['admin/config/search/verifications'] = array(
     'title' => 'Verifications',
     'description' => 'Add, change or remove verifications for your site.',
@@ -12,6 +20,7 @@
     'access arguments' => array('administer site configuration'),
     'file' => 'site_verify.admin.inc',
   );
+  // Add a verification record.
   $items['admin/config/search/verifications/add'] = array(
     'title' => 'Add verification',
     'page callback' => 'drupal_get_form',
@@ -20,24 +29,31 @@
     'file' => 'site_verify.admin.inc',
     'type' => MENU_LOCAL_ACTION,
   );
+  // Direct URL to add a verification record for a specific engine.
+  // NB: This URL is not apparent in the UI, not provided as a link.
   $items['admin/config/search/verifications/add/%site_verify_engine'] = array(
     'title' => 'Add',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('site_verify_edit_form', array(), 5),
     'access arguments' => array('administer site configuration'),
     'file' => 'site_verify.admin.inc',
+    'type' => MENU_CALLBACK,
   );
+  // Edit a verification record.
   $items['admin/config/search/verifications/%site_verify/edit'] = array(
     'page callback' => 'drupal_get_form',
     'page arguments' => array('site_verify_edit_form', 4),
     'access arguments' => array('administer site configuration'),
     'file' => 'site_verify.admin.inc',
+    'type' => MENU_CALLBACK,
   );
+  // Delete a verification record.
   $items['admin/config/search/verifications/%site_verify/delete'] = array(
     'page callback' => 'drupal_get_form',
     'page arguments' => array('site_verify_delete_form', 4),
     'access arguments' => array('administer site configuration'),
     'file' => 'site_verify.admin.inc',
+    'type' => MENU_CALLBACK,
   );
 
   // Add the verification paths.
@@ -92,6 +108,85 @@
 }
 
 /**
+ * Save a site verification record.
+ *
+ * One of either $verification->meta or $verification->file must be provided.
+ * If $verification->file_contents is provided, $verification->file must not be
+ * empty.
+ *
+ * @param Object $verification
+ * @param Int    $verification->svid          opt ID to update an existing verification record.
+ * @param String $verification->engine            System-name of the engine: e.g. google, bing, etc.
+ * @param String $verification->file          opt URL path to provide a verification page (relative to Doc-root): e.g. 'foo' will be displayed at http://example.com/foo
+ * @param String $verification->file_contents opt Page contents to display on the URL provided at $verification->file
+ * @param String $verification->meta          opt Verification meta-tag to display on the home page.
+ *
+ * @return Int
+ */
+function site_verify_save(&$verification) {
+  // Validation:
+  if (!empty($verification->file_contents) && empty($verification->file)) {
+    throw new Exception('site_verify_save requires a file parameter to be provided when the file_contents parameter is supplied.');
+  }
+  if (empty($verification->file) && empty($verification->meta)) {
+    throw new Exception('site_verify_save requires either a file parameter or a meta parameter.');
+  }
+  // Validate the engine:
+  if (empty($verification->engine) || !($engine = site_verify_engine_load($verification->engine))) {
+    throw new Exception('site_verify_save requires a valid engine parameter.');
+  }
+
+  db_merge('site_verify')
+    ->key(array(
+      'svid' => (isset($verification->svid)) ? $verification->svid : NULL,
+      ))
+    ->fields(array(
+      'engine'        => $verification->engine,
+      'file'          => $verification->file,
+      'file_contents' => $verification->file_contents,
+      'meta'          => $verification->meta,
+    ))
+    ->execute();
+
+  // Clear front page caches and set the menu to be rebuilt.
+  cache_clear_all(url('<front>', array('absolute' => TRUE)), 'cache_page');
+  cache_clear_all(url(variable_get('site_frontpage', 'node'), array('absolute' => TRUE)), 'cache_page');
+  variable_set('menu_rebuild_needed', TRUE);
+
+  watchdog('site_verify', 'Verification for %engine added.', array('%engine' => $engine['name']), WATCHDOG_NOTICE);
+
+}
+
+
+/**
+ * Delete a site verification record.
+ *
+ * @param Int $svid
+ * Unique ID which identifies an existing verification record.
+ */
+function site_verify_delete($svid) {
+  $record = site_verify_load($svid);
+
+  if ($record) {
+    db_delete('site_verify')
+      ->condition('svid', $svid)
+      ->execute();
+
+    // Clear front page caches and set the menu to be rebuilt.
+    cache_clear_all(url('<front>', array('absolute' => TRUE)), 'cache_page');
+    cache_clear_all(url(variable_get('site_frontpage', 'node'), array('absolute' => TRUE)), 'cache_page');
+    variable_set('menu_rebuild_needed', TRUE);
+
+    watchdog('site_verify', 'Verification for %engine deleted.', array('%engine' => $record['engine']['name']), WATCHDOG_NOTICE);
+  }
+  else {
+    watchdog('site_verify', 'Error deleting verification: ID %svid not found.', array('%svid' => $svid), WATCHDOG_WARNING);    
+  }
+}
+
+
+
+/**
  * Menu load callback; loads engine details.
  *
  * @param $engine
@@ -176,6 +271,10 @@
   return $engines;
 }
 
+
+/**
+ * Output the page-contents a file-based custom verification page.
+ */
 function site_verify_output($svid) {
   $verification = site_verify_load($svid);
   if ($verification['file_contents'] && $verification['engine']['file_contents']) {
