From 60bfebca72f12a97c4565acfd495537c0bf15826 Mon Sep 17 00:00:00 2001
From: Lars Toomre <ltoomre@23809.no-reply.drupal.org>
Date: Fri, 6 Apr 2012 18:12:00 -0400
Subject: [PATCH] Heavy lifting on docblocks and other code style fixes.

---
 biblio.install                                     | 1738 +++++++++++++-------
 biblio.module                                      |  165 ++-
 includes/biblio.admin.inc                          |  345 ++++-
 includes/biblio.contributors.inc                   |  559 +++++--
 includes/biblio.import.export.inc                  |  187 ++-
 includes/biblio.keywords.inc                       |  152 ++-
 includes/biblio.pages.inc                          |  302 +++-
 includes/biblio.tokens.inc                         |   17 +-
 includes/biblio.util.inc                           |   65 +-
 includes/biblio_theme.inc                          |  427 ++++--
 includes/biblio_xml.inc                            |   83 +-
 includes/content.biblio.inc                        |   30 +-
 styles/biblio_style_classic.inc                    |    1 +
 tests/biblio.test                                  |   14 +-
 tests/contributor.test                             |   14 +-
 tests/import.export.test                           |   11 +-
 tests/keyword.test                                 |   12 +-
 views/biblio.views.inc                             |   55 +-
 views/biblio_handler_citation.inc                  |   10 +-
 views/biblio_handler_field.inc                     |    8 +-
 ...blio_handler_field_biblio_keyword_data_word.inc |    5 +
 views/biblio_handler_field_biblio_keyword_kid.inc  |    7 +-
 views/biblio_handler_field_biblio_type.inc         |    8 +-
 views/biblio_handler_field_contributor.inc         |    8 +-
 views/biblio_handler_field_export_link.inc         |    4 +
 ...handler_filter_biblio_contributor_auth_type.inc |    5 +
 views/biblio_handler_filter_biblio_keyword_kid.inc |   11 +-
 views/biblio_handler_filter_biblio_type.inc        |    5 +
 views/biblio_handler_filter_contributor.inc        |    5 +-
 .../biblio_handler_filter_contributor_lastname.inc |    4 +-
 views/biblio_handler_filter_contributor_uid.inc    |    4 +-
 views/biblio_handler_sort_contributor_lastname.inc |    7 +-
 32 files changed, 3016 insertions(+), 1252 deletions(-)

diff --git a/biblio.install b/biblio.install
index 7aa160a..8eeae15 100644
--- a/biblio.install
+++ b/biblio.install
@@ -1,28 +1,43 @@
 <?PHP
-
 /**
  * @file
- *  Install file for biblio module
+ * Install, update, and uninstall functions for the biblio module.
  */
 
+// @todo: Add reference to Drupal version and time of last edit?
+
+/**
+ * Implements hook_install().
+ */
 function biblio_install() {
   $result = array();
 
-  drupal_install_schema('biblio');
+  // Create the database tables that will store data for the biblio module.
+  $result[] = drupal_install_schema('biblio');
 
-  $result[] = _add_db_field_data();
+  // There are numerous bibliographic types. Initialize the {biblio_types} table
+  // with an initial list of bibliographic types.
+  $result[] = _biblio_add_bibliographic_types();
 
-  $result[] = _add_publication_types();
+  // Each type of biblio publication (for example, a book) may have one or more
+  // fields associated with it, such as title, ISBN number, etc. Hence, set up
+  // definition parameters about how a title, ISBN, etc. are defined as a custom
+  // biblio field.
+  $result[] = _biblio_add_field_definitions();
 
-  $result[] = _add_custom_field_data();
+  // With the types of custom biblio fields now defined, we need to set which
+  // custom biblio fields are to be used with each bibliographic type and adjust
+  // the field labels as appropriate.
+  $result[] = _biblio_types_customize_fields();
 
-  //_enable_biblio_keyword_vocabulary();
-
-  $result[] = _set_system_weight();
+  // Drupal hooks are processed by modules as they are set in the system table
+  // in order of the module weight.  Those with heavier wights are called later
+  // in the sequence.  Increase the weight of this module for a later call.
+  $result[] = _biblio_set_module_system_weight();
 
+  // Install the helper modules associated with the main biblio module.
   _biblio_helper_modules('install');
 
-
   if (count($result) == count(array_filter($result))) {
     drupal_set_message(t('The biblio module has successfully added its tables to the database.'));
   }
@@ -31,17 +46,25 @@ function biblio_install() {
   }
 }
 
+/**
+ * Implements hook_enable().
+ */
 function biblio_enable() {
-  if (module_exists('taxonomy')) _enable_biblio_vocabularies();
-  _set_system_weight();
-  //_enable_biblio_collection_vocabulary();
- // _add_biblio_keywords();
+  if (module_exists('taxonomy')) {
+    _biblio_enable_vocabularies();
+  }
+
+  // Adjust the weight of the biblio module in the collection of modules.
+  _biblio_set_module_system_weight();
 }
 
-function _enable_biblio_vocabularies() {
+/**
+ * Helper function to enable vocabularies for the biblio module.
+ */
+function _biblio_enable_vocabularies() {
   $vids = variable_get('biblio_vocabularies', array());
   foreach ($vids as $vid ) {
-    if (($voc = taxonomy_vocabulary_load($vid)))  {
+    if (($voc = taxonomy_vocabulary_load($vid))) {
       $voc = (array) $voc;
       $voc['nodes']['biblio'] = 1;
       taxonomy_save_vocabulary($voc);
@@ -49,11 +72,14 @@ function _enable_biblio_vocabularies() {
   }
 }
 
+/**
+ * Implements hook_disable().
+ */
 function biblio_disable() {
   if (module_exists('taxonomy')) {
     $voc = taxonomy_get_vocabularies();
     foreach ($voc as $vid => $vocabulary) {
-      if (isset($vocabulary->nodes['biblio']))  {
+      if (isset($vocabulary->nodes['biblio'])) {
         $vids[] = $vid;
       }
     }
@@ -61,11 +87,16 @@ function biblio_disable() {
   }
 }
 
+/**
+ * Implements hook_uninstall().
+ */
 function biblio_uninstall() {
   if (module_exists('taxonomy')) {
     $voc = taxonomy_get_vocabularies();
     foreach ($voc as $vid => $vocabulary) {
-      if ($vocabulary->module == 'biblio')  taxonomy_del_vocabulary($vid);
+      if ($vocabulary->module == 'biblio') {
+        taxonomy_del_vocabulary($vid);
+      }
     }
   }
 
@@ -89,15 +120,18 @@ function biblio_uninstall() {
   }
 
   cache_clear_all();
-
 }
+
+/**
+ * Implements hook_requirements().
+ */
 function biblio_requirements($phase) {
   $requirements = array();
   $message = '';
- // Ensure translations don't break at install time
+  // Ensure translations do not break at install time.
   $t = get_t();
 
-  // Report Drupal version
+  // @todo: When is this requirement check called?
   if ($phase == 'runtime') {
     $dir = drupal_get_path('module', 'biblio');
     $files = file_scan_directory($dir, '..*.inc$',  array('.', '..'), 0, FALSE);
@@ -110,31 +144,39 @@ function biblio_requirements($phase) {
       $message .= "</ul>";
     }
     $requirements['biblio'] = array(
-        'title' => $t('Biblio'),
-        'value' => BIBLIO_VERSION,
-        'severity' => empty($message) ? REQUIREMENT_OK : REQUIREMENT_ERROR,
-        'description' => $message,
+      'title' => $t('Biblio'),
+      'value' => BIBLIO_VERSION,
+      'severity' => empty($message) ? REQUIREMENT_OK : REQUIREMENT_ERROR,
+      'description' => $message,
     );
-
   }
   return $requirements;
 }
 
+/**
+ * Helper function to assist in installation and removal of helper modules.
+ */
 function _biblio_helper_modules($mode) {
-
   $modules = _biblio_get_helper_modules();
   switch ($mode) {
     case 'install':
       drupal_install_modules($modules);
       break;
+
     case 'uninstall':
       foreach($modules as $module) {
         drupal_uninstall_module($module);
       }
       break;
+
+    default:
+      break;
   }
 }
 
+/**
+ * Helper function to define helper sub-modules of biblio module.
+ */
 function _biblio_get_helper_modules() {
   return array(
     'biblio_bibtex',
@@ -150,53 +192,42 @@ function _biblio_get_helper_modules() {
 
 }
 
-function _set_system_weight() {
+/**
+ * Helper function to adjust the system weight value of biblio module.
+ */
+function _biblio_set_module_system_weight() {
   return update_sql("UPDATE {system} SET weight = 9 WHERE name = 'biblio'");
 }
 
-
-function _enable_biblio_keyword_vocabulary(){
-
+/**
+ * Helper function to enable the keyword vocabulary for the biblio module.
+ */
+function _biblio_enable_keyword_vocabulary() {
 
   if ($vocabulary = taxonomy_vocabulary_load(variable_get('biblio_keyword_vocabulary', 0))) {
-      // Existing install. Add back forum node type, if the biblio
-    // vocabulary still exists. Keep all other node types intact there.
+    // Existing install. Add back forum node type, if the biblio vocabulary
+    // still exists. Keep all other node types intact there.
     $vocabulary = (array) $vocabulary;
     $vocabulary['nodes']['biblio'] = 1;
     taxonomy_save_vocabulary($vocabulary);
   }
-//  else {
-//    // Create the biblio vocabulary if it does not exist.
-//    $vocabulary = array(
-//      'name' => 'Biblio Keywords',
-//      'description' => t('This is a free tag vocabulary which contains the keywords from all nodes created by the biblio module'),
-//      'help' => t('Enter a comma separated list of words. Phrases containing commas should be enclosed in double quotes'),
-//      'nodes' => array('biblio' => 1),
-//      'hierarchy' => 0,
-//      'relations' => 1,
-//      'tags' => 1,
-//      'multiple' => 0,
-//      'required' => 0,
-//      'weight' => 0,
-//      'module' => 'biblio',
-//    );
-//    taxonomy_save_vocabulary($vocabulary);
-//    variable_set('biblio_keyword_vocabulary', $vocabulary['vid']);
-//  }
   return $vocabulary['vid'];
 }
-function _enable_biblio_collection_vocabulary() {
+
+/**
+ * Helper function to eneable the collection vocabulary for the biblio modules.
+ */
+function _biblio_enable_collection_vocabulary {
   if ($vocabulary = taxonomy_vocabulary_load(variable_get('biblio_collection_vocabulary', 0))) {
-    // Existing install. Add back forum node type, if the biblio
-    // vocabulary still exists. Keep all other node types intact there.
+    // Existing install. Add back forum node type, if the biblio vocabulary
+    // still exists. Keep all other node types intact there.
     $vocabulary = (array) $vocabulary;
     $vocabulary['nodes']['biblio'] = 1;
     taxonomy_save_vocabulary($vocabulary);
   }
   else {
-    // Create the forum vocabulary if it does not exist. Assign the vocabulary
-    // a low weight so it will appear first in forum topic create and edit
-    // forms.
+    // Create the forum vocabulary if it does not exist. Assign the vocabulary a
+    // low weight so it will appear first in forum topic create and edit forms.
     $vocabulary = array(
       'name' => 'Biblio Collections',
       'description' => 'You may organize your publications into collections by adding a collection names to this vocabulary',
@@ -224,35 +255,40 @@ function _enable_biblio_collection_vocabulary() {
     taxonomy_save_term($default_collection);
   }
   return $vocabulary['vid'];
-
 }
 
 /**
- * Copies keywords from the biblio_keyword column of the biblio table
- * to a taxonomy vocabulary
+ * Helper function to transfer biblio_keyword data to taxonomy vocabulary.
+
+ * This function copies keywords from the biblio_keyword column of the biblio
+ * table to a taxonomy vocabulary.
  *
- * @return none
+ * @return array
+ *   An associative array with two elements:
+ *   - success: A boolean indicating success of the process.
+ *   - query: A message about the condition of the process.
  */
-function _add_biblio_keywords() {
+function _biblio_add_keywords() {
   set_time_limit(300);
   $kw_sep = variable_get('biblio_keyword_sep', ',');
-  $vid = ($vid = variable_get('biblio_keyword_vocabulary', 0))? $vid:_enable_biblio_keyword_vocabulary();
-  if ($vid ) {
-    $db_result  = db_query("SELECT b.biblio_keywords, b.nid, b.vid FROM {biblio} b");
+  $vid = ($vid = variable_get('biblio_keyword_vocabulary', 0)) ? $vid : _biblio_enable_keyword_vocabulary();
+  if ($vid) {
+    $db_result = db_query("SELECT b.biblio_keywords, b.nid, b.vid FROM {biblio} b");
     $result = array();
     while ($row = db_fetch_object($db_result)) {
-      foreach(explode($kw_sep, $row->biblio_keywords) as $keyword) {
-        $result[] = array('value' => trim($keyword), 'nid' => $row->nid, 'vid' =>$row->vid);
+      foreach (explode($kw_sep, $row->biblio_keywords) as $keyword) {
+        $result[] = array('value' => trim($keyword), 'nid' => $row->nid, 'vid' => $row->vid);
       }
       db_query('DELETE tn.* FROM {term_node} tn INNER JOIN {term_data} td ON tn.tid = td.tid WHERE nid = %d AND td.vid = %d', $row->nid, $vid);
     }
     $inserted = array();
     $count = 0;
     foreach ($result as $keywords) {
-      // See if the term exists in the chosen vocabulary
-      // and return the tid; otherwise, add a new record.
+      // See if the term exists in the chosen vocabulary and return the tid;
+      // otherwise, add a new record.
       $possibilities = taxonomy_get_term_by_name($keywords['value']);
-      $term_tid = NULL; // tid match, if any.
+      // Used in determining a tid match (if any).
+      $term_tid = NULL;
       foreach ($possibilities as $possibility) {
         if ($possibility->vid == $vid) {
           $term_tid = $possibility->tid;
@@ -265,7 +301,7 @@ function _add_biblio_keywords() {
         $term_tid = $term['tid'];
       }
 
-      // Defend against duplicate, differently cased tags
+      // Defend against duplicate and differently capitalized tags
       if (!isset($inserted[$keywords['vid']][$term_tid])) {
         db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $keywords['nid'], $keywords['vid'], $term_tid);
         $inserted[$keywords['vid']][$term_tid] = TRUE;
@@ -277,341 +313,342 @@ function _add_biblio_keywords() {
   return array('success' => FALSE, 'query' => 'Biblio keyword vocabulary not available');
 }
 
-
-
+/**
+ * Implements hook_schema().
+ *
+ * The indentation in biblio_schema() slighlty varies from Drupal coding
+ * conventions, but has been adjusted so all indetion here is consistent.
+ *
+ * @return array
+ *   An associative array with data base table schemas defined for the biblio
+ *   module keyed by the name of the data base tble.
+ */
 function biblio_schema() {
   $schema['biblio'] = array(
+    // @todo: Missing description?
     'fields' => array(
       'nid' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
         'description' => '',
-  ),
+        ),
       'vid' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
         'description' => '',
-  ),
+        ),
       'biblio_type' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
         'description' => '',
-  ),
+        ),
       'biblio_number' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_other_number' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_sort_title' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '64',
         'description' => 'A normalized version of the title, used for sorting on titles. (only first 64 characters saved)',
-  ),
+        ),
       'biblio_secondary_title' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_tertiary_title' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_edition' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_publisher' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_place_published' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_year' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 9999,
         'description' => '',
-  ),
+        ),
       'biblio_volume' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_pages' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_date' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '64',
         'description' => '',
-  ),
+        ),
       'biblio_isbn' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_lang' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '24',
         'default' => 'eng',
         'description' => '',
-  ),
+        ),
       'biblio_abst_e' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_abst_f' => array(
         'not null' => FALSE,
         'type' => 'text',
         'description' => '',
-  ),
+        ),
       'biblio_full_text' => array(
         'type' => 'int',
         'not null' => FALSE,
         'default' => 0,
         'description' => '',
-  ),
+        ),
       'biblio_url' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_issue' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_type_of_work' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_accession_number' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_call_number' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_notes' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom1' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom2' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom3' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom4' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom5' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom6' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_custom7' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_research_notes' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_number_of_volumes' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_short_title' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_alternate_title' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_original_publication' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_reprint_edition' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_translated_title' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_section' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_citekey' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_coins' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_doi' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_issn' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '128',
         'description' => '',
-  ),
+        ),
       'biblio_auth_address' => array(
         'type' => 'text',
         'not null' => FALSE,
         'description' => '',
-  ),
+        ),
       'biblio_remote_db_name' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_remote_db_provider' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_label' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
       'biblio_access_date' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '255',
         'description' => '',
-  ),
+        ),
      'biblio_refereed' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '20',
         'description' => '',
-  ),
+        ),
       'biblio_md5' => array(
         'type' => 'varchar',
         'not null' => FALSE,
         'length' => '32',
         'description' => '',
-  ),
+        ),
       'biblio_formats' => array(
         'type' => 'blob',
         'not null' => FALSE,
         'description' => '',
         'serialize' => TRUE,
+        ),
     ),
-  ),
-    'primary key' => array(
-      'vid'
-      ),
+    'primary key' => array('vid'),
     'indexes' => array(
-      'nid' => array(
-        'nid'
-        ),
-      'md5' => array(
-        'biblio_md5'
-        ),
-      'year' => array(
-        'biblio_year'
-        )
-        ),
-
-        );
+      'nid' => array('nid'),
+      'md5' => array('biblio_md5'),
+      'year' => array('biblio_year'),
+    ),
+  );
 
-   $schema['biblio_fields'] = array(
+  $schema['biblio_fields'] = array(
+    // @todo: Missing description?
     'fields' => array(
       'fid' => array(
         'type' => 'int',
         'not null' => TRUE,
-          'unsigned' => TRUE,
+        'unsigned' => TRUE,
         'default' => 0,
         'description' => '{biblio_fields}.fid of the node',
         ),
@@ -639,11 +676,11 @@ function biblio_schema() {
         'unsigned' => TRUE,
         'default' => 255,
         ),
-        ),
-      'primary key' => array('fid'),
-        );
+    ),
+    'primary key' => array('fid'),
+  );
 
-   $schema['biblio_field_type'] = array(
+  $schema['biblio_field_type'] = array(
     'description' => 'Relational table linking {biblio_fields} with {biblio_field_type_data}',
     'fields' => array(
       'tid' => array(
@@ -706,21 +743,20 @@ function biblio_schema() {
         'default' => 0,
         'description' => 'Determines if the field is visible on the input form'
         ),
-
-        ),
+    ),
     'primary key' => array('tid', 'fid'),
     'indexes' => array(
       'tid' => array('tid')
-        ),
-        );
+    ),
+  );
 
-   $schema['biblio_field_type_data'] = array(
+  $schema['biblio_field_type_data'] = array(
     'description' => 'Data used to build the form elements on the input form',
     'fields' => array(
       'ftdid' => array(
         'type' => 'int',
         'not null' => TRUE,
-          'unsigned' => TRUE,
+        'unsigned' => TRUE,
         'default' => 0,
         'description' => '{biblio_field_type_data}.ftdid of the node',
         ),
@@ -737,13 +773,14 @@ function biblio_schema() {
         'not null' => FALSE,
         'description' => 'The hint text printed below the input widget'
         ),
-        ),
+    ),
     'primary key' => array('ftdid'),
-        );
+  );
 
   $schema['biblio_types'] = array(
+    // @todo: Missing description?
     'fields' => array(
-        'tid' => array(
+      'tid' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
@@ -775,16 +812,13 @@ function biblio_schema() {
         'default' => 1,
         'description' => 'Determines if the publication type is visible in the list'
         ),
-        ),
-      'primary key' => array('tid'),
-
-        );
-
-
+    ),
+    'primary key' => array('tid'),
+  );
 
- $schema['biblio_contributor'] = array(
-  'description' => 'Relational table linking authors to biblio entries',
-  'fields' => array(
+  $schema['biblio_contributor'] = array(
+    'description' => 'Relational table linking authors to biblio entries',
+    'fields' => array(
       'nid' => array(
         'type' => 'int',
         'not null' => TRUE,
@@ -799,37 +833,37 @@ function biblio_schema() {
         'default' => 0,
         'description' => '{node}.vid of the node',
         ),
-        'cid' => array(
+      'cid' => array(
         'type' => 'int',
         'not null' => TRUE,
         'unsigned' => TRUE,
         'default' => 0,
         'description' => '{biblio_contributor_data}.cid of the node',
         ),
-        'auth_type' => array(
+      'auth_type' => array(
         'type' => 'int',
         'not null' => TRUE,
         'unsigned' => TRUE,
         'default' => 1,
         'description' => '{biblio_contributor_type}.auth_type of the node',
         ),
-        'auth_category' => array(
+      'auth_category' => array(
         'type' => 'int',
         'not null' => TRUE,
         'unsigned' => TRUE,
         'default' => 1,
         'description' => '',
         ),
-        'rank' => array(
+      'rank' => array(
         'type' => 'int',
         'not null' => TRUE,
         'unsigned' => TRUE,
         'default' => 0,
         'description' => 'Position of the author name on the publication (first,second,third...)',
         )
-        ),
-      'primary key' => array('vid', 'cid', 'auth_type', 'rank'),
-        );
+    ),
+    'primary key' => array('vid', 'cid', 'auth_type', 'rank'),
+  );
 
   $schema['biblio_contributor_data'] = array(
     'description' => 'Contains Author information for each publication',
@@ -915,44 +949,42 @@ function biblio_schema() {
         'not null' => FALSE,
         'description' => '',
         )
+    ),
+    'primary key' => array('cid', 'aka'),
+    'indexes' => array(
+      'lastname' => array('lastname'),
+      'firstname' => array('firstname'),
+      'initials' => array('initials')
+    )
+  );
 
+  $schema['biblio_contributor_type'] = array(
+    'description' => 'Contains definitions of the contributor types',
+    'fields' => array(
+      'auth_category' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => 'There are 5 catagoies of author: Primary, Secondary, Tertiery, Subsidary and Corporate  ',
         ),
-      'primary key' => array('cid', 'aka'),
-      'indexes' => array(
-          'lastname' => array('lastname'),
-          'firstname' => array('firstname'),
-          'initials' => array('initials')
-
-        )
-        );
-    $schema['biblio_contributor_type'] = array(
-      'description' => 'Contains definitions of the contributor types',
-      'fields' => array(
-        'auth_category' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => 'There are 5 catagoies of author: Primary, Secondary, Tertiery, Subsidary and Corporate  ',
-        ),
-        'biblio_type' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => '',
-        ),
-        'auth_type' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => 'This is the pulication type specific verion of a particular catagory',
+      'biblio_type' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => '',
         ),
+      'auth_type' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => 'This is the pulication type specific verion of a particular catagory',
         ),
+    ),
     'primary key' => array('auth_category', 'biblio_type', 'auth_type'),
-
-        );
+  );
 
   $schema['biblio_contributor_type_data'] = array(
     'description' => 'Data used to build the form elements on the input form',
@@ -976,221 +1008,237 @@ function biblio_schema() {
         'not null' => FALSE,
         'description' => 'The hint text printed below the input widget'
         ),
-        ),
+    ),
     'primary key' => array('auth_type'),
-        );
+  );
 
-    $schema['biblio_keyword'] = array(
-      'description' => t('Relational table linking keywords to biblio nodes'),
-      'fields' => array(
-        'kid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('Primary Key: The {biblio_keyword_data}.kid of the keyword of the node.')
-        ),
-        'nid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('The {node}.nid of the node.'),
-        ),
-        'vid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('Primary Key: The {node}.vid of the node.'),
+  $schema['biblio_keyword'] = array(
+    'description' => t('Relational table linking keywords to biblio nodes'),
+    'fields' => array(
+      'kid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The {biblio_keyword_data}.kid of the keyword of the node.')
         ),
+      'nid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('The {node}.nid of the node.'),
         ),
-      'primary key' => array('kid', 'vid'),
-      'indexes' => array(
-           'vid' => array('vid'),
-           'nid' => array('nid'),
+      'vid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The {node}.vid of the node.'),
         ),
-        );
+    ),
+    'primary key' => array('kid', 'vid'),
+    'indexes' => array(
+       'vid' => array('vid'),
+       'nid' => array('nid'),
+    ),
+  );
 
-     $schema['biblio_keyword_data'] = array(
-      'description' => t('Stores the keywords related to nodes.'),
-      'fields' => array(
-        'kid' => array(
-          'type' => 'serial',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'description' => t('Primary Key: The id of the keyword assigned to the node')
-        ),
-        'word' => array(
-          'type' => 'varchar',
-          'length' => 255,
-          'not null' => TRUE,
-          'default' => '',
-          'description' => t('The keyword'),
-        ),
-        ),
-      'primary key' => array('kid'),
-      'indexes' => array(
-           'kword' => array('word'),
-        ),
-        );
-     $schema['biblio_collection'] = array(
-      'description' => t('Relational table grouping biblio nodes into collections'),
-      'fields' => array(
-        'cid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('Primary Key: The {biblio_collection_data}.cid of the collection')
-        ),
-        'vid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('Primary Key: The {node}.vid of the node.'),
-        ),
-        'pid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('The parent id of the collection')
-        ),
-        'nid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('The {node}.nid of the node.'),
-        ),
-        ),
-      'primary key' => array('cid', 'vid'),
-      'indexes' => array(
-           'pid' => array('pid'),
-           'nid' => array('nid'),
-        ),
-        );
-     $schema['biblio_collection_type'] = array(
-      'description' => t('Descriptions of the collections.'),
-      'fields' => array(
-        'cid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('Primary Key: The id of the collection')
-        ),
-        'name' => array(
-          'type' => 'varchar',
-          'length' => 255,
-          'not null' => TRUE,
-          'default' => '',
-          'description' => t('The name of the collection'),
-        ),
-        'description' => array(
-          'type' => 'varchar',
-          'length' => 255,
-          'not null' => TRUE,
-          'default' => '',
-          'description' => t('The description of the collection'),
+  $schema['biblio_keyword_data'] = array(
+    'description' => t('Stores the keywords related to nodes.'),
+    'fields' => array(
+      'kid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'description' => t('Primary Key: The id of the keyword assigned to the node')
         ),
+      'word' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The keyword'),
+      ),
+    ),
+    'primary key' => array('kid'),
+    'indexes' => array(
+      'kword' => array('word'),
+    ),
+  );
+
+  $schema['biblio_collection'] = array(
+    'description' => t('Relational table grouping biblio nodes into collections'),
+    'fields' => array(
+      'cid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The {biblio_collection_data}.cid of the collection')
         ),
-      'primary key' => array('cid'),
-      'indexes' => array(
-           'name' => array('name'),
+      'vid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The {node}.vid of the node.'),
         ),
-        );
-    $schema['biblio_duplicates'] = array(
-      'description' => t('Relational table linking possible duplicate biblio nodes'),
-      'fields' => array(
-        'vid' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('Primary Key: The {biblio}.nid of the original node')
+      'pid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('The parent id of the collection')
         ),
-        'did' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('The {biblio}.nid of the newly imported node which may be a duplicate.'),
+      'nid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('The {node}.nid of the node.'),
         ),
-        'type' => array(
-          'type' => 'int',
-          'not null' => TRUE,
-          'unsigned' => TRUE,
-          'default' => 0,
-          'description' => t('The type of duplicate 0=biblio, 1=author.'),
-        ),
-        ),
-      'primary key' => array('vid', 'did'),
-        'indexes' => array(
-           'did' => array('vid'),
-        ),
-        );
-
-      $schema['biblio_import_cache'] = array(
-        'description' => 'tables used for caching data imported from file and then batch processed',
-        'fields' => array(
-          'id' => array(
-            'type' => 'serial',
-            'not null' => TRUE,
-            'unsigned' => TRUE),
-          'session_id' => array(
-            'type' => 'varchar',
-            'length' => 45,
-            'not null' => TRUE),
-          'data' => array(
-            'description' => t('A collection of data to cache.'),
-            'type' => 'blob',
-            'not null' => FALSE,
-            'size' => 'big'),
-        ),
-        'primary key' => array('id'));
+    ),
+    'primary key' => array('cid', 'vid'),
+    'indexes' => array(
+      'pid' => array('pid'),
+      'nid' => array('nid'),
+    ),
+  );
 
-  $schema['biblio_type_maps'] = array(
+  $schema['biblio_collection_type'] = array(
+    'description' => t('Descriptions of the collections.'),
+    'fields' => array(
+      'cid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The id of the collection')
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The name of the collection'),
+      ),
+      'description' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+        'description' => t('The description of the collection'),
+      ),
+    ),
+    'primary key' => array('cid'),
+    'indexes' => array(
+      'name' => array('name'),
+    ),
+  );
+
+  $schema['biblio_duplicates'] = array(
+    'description' => t('Relational table linking possible duplicate biblio nodes'),
+    'fields' => array(
+      'vid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('Primary Key: The {biblio}.nid of the original node')
+        ),
+      'did' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('The {biblio}.nid of the newly imported node which may be a duplicate.'),
+      ),
+      'type' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+        'description' => t('The type of duplicate 0=biblio, 1=author.'),
+      ),
+    ),
+    'primary key' => array('vid', 'did'),
+    'indexes' => array(
+      'did' => array('vid'),
+    ),
+  );
+
+  $schema['biblio_import_cache'] = array(
+    'description' => 'tables used for caching data imported from file and then batch processed',
+    'fields' => array(
+      'id' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'unsigned' => TRUE),
+        'session_id' => array(
+          'type' => 'varchar',
+          'length' => 45,
+          'not null' => TRUE,
+          ),
+        'data' => array(
+          'description' => t('A collection of data to cache.'),
+          'type' => 'blob',
+          'not null' => FALSE,
+          'size' => 'big',
+        ),
+    ),
+    'primary key' => array('id'),
+  );
+
+  $schema['biblio_type_maps'] = array(
     'description' => 'Table used to store the mapping information between various file formats and the biblio schema',
     'fields' => array(
       'format' => array(
         'description' => 'The import/export file format',
         'type' => 'varchar',
         'length' => 128,
-        'not null' => TRUE),
+        'not null' => TRUE,
+        ),
       'type_map' => array(
         'description' => 'The mapping between the publication types in the file format and biblio',
         'type' => 'blob',
         'not null' => FALSE,
-        'size' => 'big'),
+        'size' => 'big',
+        ),
       'type_names' => array(
         'description' => 'The human readable names of the publication types',
         'type' => 'blob',
         'not null' => FALSE,
-        'size' => 'big'),
+        'size' => 'big',
+        ),
       'field_map' => array(
         'description' => 'The mapping between the fields in the file format and biblio',
         'type' => 'blob',
         'not null' => FALSE,
-        'size' => 'big'),
+        'size' => 'big',
+        ),
       'export_map' => array(
         'description' => 'which fields are exported',
         'type' => 'blob',
         'not null' => FALSE,
-        'size' => 'big'),
-      ),
-    'primary key' => array('format'));
+        'size' => 'big',
+        ),
+    ),
+    'primary key' => array('format'),
+  );
 
   $schema['cache_biblio_csl_object'] = drupal_get_schema_unprocessed('system', 'cache');
   $schema['cache_biblio_csl_object']['description'] = 'Cache table for biblio to store pre-built csl objects.';
   $schema['cache_biblio_csl_object']['fields']['serialized']['default'] = 1;
 
-   return ($schema);
-
+  return $schema;
 }
 
+/**
+ * Helper function to reset all field defintions to their defaults.
+ *
+ * @see biblio_admin_types_reset_form_submit()
+ */
 function biblio_reset_types() {
   $result = array();
 
@@ -1207,25 +1255,38 @@ function biblio_reset_types() {
   db_create_table($result, 'biblio_contributor_type', $schema['biblio_contributor_type']);
   db_create_table($result, 'biblio_contributor_type_data', $schema['biblio_contributor_type_data']);
 
-  variable_set('biblio_last_ftdid', 100); // reset custom field type id too
-  //_add_db_field_data_XML();
-  _add_db_field_data();
-  _add_custom_field_data();
+  // Also reset the custom field type ID
+  variable_set('biblio_last_ftdid', 100);
+  _biblio_add_field_definitions();
+  _biblio_types_customize_fields();
 }
 
-function _add_publication_types() {
+/**
+ * Defines data for initial collection of biblio publication types.
+ *
+ * @return array
+ *   An array of publication types where each publication type is an array that
+ *   includes (in order) data about:
+ *   - tid: The ID of the publication type.
+ *   - name: The name of the publication type.
+ *   - description: Controls the order the types are listed in.
+ *   - weight: Controls the order the types are listed in.
+ */
+function _biblio_data_bibliographic_types() {
+  $types = array();
+  // Definitions about types of bibliographic material.
   $types[] = array(100, 'Book', NULL, 1);
   $types[] = array(101, 'Book Chapter', NULL, 2);
   $types[] = array(102, 'Journal Article', NULL, 3);
-  $types[] = array(131,'Journal',NULL,3);
+  $types[] = array(131, 'Journal', NULL, 3);
   $types[] = array(103, 'Conference Paper', NULL, 4);
   $types[] = array(104, 'Conference Proceedings', NULL, 5);
   $types[] = array(105, 'Newspaper Article', NULL, 6);
   $types[] = array(106, 'Magazine Article', NULL, 7);
   $types[] = array(107, 'Web Article', NULL, 8);
-  $types[] = array(132,'Website',NULL,8);
-  $types[] = array(133,'Web service',NULL,8);
-  $types[] = array(134,'Web project page',NULL,8);
+  $types[] = array(132, 'Website', NULL, 8);
+  $types[] = array(133, 'Web service', NULL, 8);
+  $types[] = array(134, 'Web project page', NULL, 8);
   $types[] = array(108, 'Thesis', NULL, 9);
   $types[] = array(109, 'Report', NULL, 10);
   $types[] = array(110, 'Film', NULL, 11);
@@ -1249,172 +1310,319 @@ function _add_publication_types() {
   $types[] = array(128, 'Legal Ruling', NULL, 29);
   $types[] = array(129, 'Miscellaneous',NULL, 30);
   $types[] = array(130, 'Miscellaneous Section', NULL, 31);
-  $types[] = array(135,'Presentation',NULL,8);
+  $types[] = array(135, 'Presentation', NULL, 8);
 
-  foreach($types as $record)
-  {
+  return $types;
+}
+
+/**
+ * Populates {biblio_types} table with initial bibliographvic type data.
+ *
+ * @return array
+ *   An array of arrays with data summarizing attempts to insert records into
+ *   {biblio_types} table where each array has the following key/value pairs:
+ *   - success: A boolean indicating whether the query succeeded.
+ *   - query: The SQL query(s) executed, passed through check_plain().
+ */
+function _biblio_add_bibliographic_types() {
+  $result = array();
+  $types = _biblio_data_bibliographic_types();
+  foreach ($types as $record) {
     $result[] = update_sql("INSERT INTO {biblio_types} (tid, name, description, weight) VALUES ('" . implode("', '", $record) . "')");
   }
- return $result;
+  return $result;
 }
 
-
-function _add_db_field_data() {
+/**
+ * Adds biblio field definitions to fields tables based upon data in a CSV file.
+ *
+ * This function reads data from the CSV file biblio.field.link.data.csv and
+ * uses that information to create field type definitions as well as contributor
+ * type definition records in the appropriate field-related tables for the
+ * biblio module.
+ *
+ * @return array
+ *   An array of data summarizing attempts to add custom field data to tables
+ *   with the following keys:
+ *   - success: A boolean indicating success in this operation.
+ *   - query: A message string with further information about operation success.
+ */
+function _biblio_add_field_definitions() {
   global $db_type;
+  $csv_file = drupal_get_path('module', 'biblio') . '/misc/biblio.field.link.data.csv';
+
+  // Immediately return if handle to CSV file cannot be obtained.
+  if ($handle = fopen($csv_file, "r") === FALSE) {
+    $result = array('success' => FALSE, 'query' => 'Could not open CSV file ' . $csv_file);
+    return $result;
+  }
+
+  // Get the column names of all three biblio tables used for defining fields.
   $schema = biblio_schema();
-  $fieldnames = array_keys($schema['biblio_fields']['fields']);
-  $field_type_fieldnames = array_keys($schema['biblio_field_type']['fields']);
-  $field_type_data_fieldnames = array_keys($schema['biblio_field_type_data']['fields']);
+  $fields_columns = array_keys($schema['biblio_fields']['fields']);
+  $field_type_columns = array_keys($schema['biblio_field_type']['fields']);
+  $field_type_data_columns = array_keys($schema['biblio_field_type_data']['fields']);
+
+  // @todo: Add comment explaining these non-obvious queries.
   if ($db_type == 'mysql' or $db_type == 'mysqli') {
     db_query("/*!40000 ALTER TABLE {biblio_field_type_data} DISABLE KEYS */;");
     db_query("/*!40000 ALTER TABLE {biblio_fields} DISABLE KEYS */;");
   }
-  $csv_file = drupal_get_path('module', 'biblio') .'/misc/biblio.field.link.data.csv';
 
-  if ($handle = fopen($csv_file, "r")) {
-    $header = fgetcsv($handle, 10000, ","); // the first line has the field names
-    while (($row = fgetcsv($handle, 10000, ",")) !== FALSE) {
-      $column = 0;
-      // add link data for default biblio type (0) and all other defined types (100-130)
-      foreach (array_merge(array(0), range(100,130)) as $t) {
-        $link_data = array($t,$row[0],$row[0],$row[0],$row[3],$row[4],$row[5],$row[6],$row[7]);
-        db_query("INSERT INTO {biblio_field_type} (". implode(", ", $field_type_fieldnames) . ")
-                  VALUES ('" . implode("', '", $link_data) . "')");
-      }
-      $ftd = array($row[0],$row[1],$row[2]);
-      db_query("INSERT INTO {biblio_field_type_data} (" . implode(", ", $field_type_data_fieldnames) . ")
-                  VALUES('" . implode("', '", $ftd) . "')");
-      $field_data = array($row[0],$row[8],$row[9],$row[10],$row[11]);
-      db_query("INSERT INTO {biblio_fields} (" . implode(", ", $fieldnames) . ")
-                  VALUES('" . implode("', '", $field_data) . "')");
-
-      // add contributor type data
-      if ($row[9] == 'contrib_widget') {
-        // use field name without trailing 's' as initial guess for author type
-        $auth_type = (substr($row[1],-1,1) == 's') ? substr($row[1],0,-1) : $row[1];
-        db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", $row[0], $auth_type);
-        db_query("INSERT INTO {biblio_contributor_type} (auth_category, biblio_type, auth_type) VALUES (%d, %d, %d)", $row[0], 0, $row[0]);
-      }
+  // Prepare array keyed by IDs of bibliographic types.
+  $biblio_types = array();
+  foreach (_biblio_data_bibliographic_types() as $key => $type) {
+    $biblio_types[$type[0]] = $type[1];
+  }
+
+  // The first line of CSV files contains the field names.
+  $header = fgetcsv($handle, 10000, ",");
+  while (($row = fgetcsv($handle, 10000, ",")) !== FALSE) {
+    $column = 0;
+
+    // Add data for both the default biblio type (0) and all other biblio types
+    // defined in _biblio_data_bibliographic_types().
+    foreach (array_merge(array(0), array_keys($biblio_types)) as $t) {
+      $field_type_values = array(
+        $t,       // tid: ID of the bibliographic type.
+        $row[0],  // fid: {biblio_fields}.fid of the node.
+        $row[0],  // ftdid: {biblio_field_type_data}.ftdid of the node, points to the current data, default or custom.
+        $row[0],  // cust_tdid: This always points to the custom data for this field. Stored so we can switch back an forth between default and custom.
+        $row[3],  // common:
+        $row[4],  // autocomplete:
+        $row[5],  // required: Is input required for this field?
+        $row[6],  // weight: The weight (location) of the field on the input form.
+        $row[7],  // visible: Whether this field is visible in this instance.
+      );
+      db_query("INSERT INTO {biblio_field_type} (". implode(", ", $field_type_columns) . ") " .
+               "VALUES ('" . implode("', '", $field_type_values) . "')");
     }
-    fclose($handle);
-    $result = array('success' => TRUE, 'query' => 'Added field titles and default values');
 
+    $field_type_data_values = array(
+      $row[0],  // ftdid: ID of this type of field.
+      $row[1],  // title: The title, which will be displayed on the form, for a given field.
+      $row[2],  // hint: The hint text printed below the input widget.
+    );
+    db_query("INSERT INTO {biblio_field_type_data} (" . implode(", ", $field_type_data_columns) . ") " .
+             "VALUES('" . implode("', '", $field_type_data_values) . "')");
+
+    $fields_values = array(
+      $row[0],   // fid: ID of this type of field.
+      $row[8],   // name: Name of this type of field.
+      $row[9],   // type: Type of form element for entering data for this field.
+      $row[10],  // size: Default size of this form element.
+      $row[11],  // maxsize: Maximum size of this form element.
+    );
+    db_query("INSERT INTO {biblio_fields} (" . implode(", ", $fields_columns) . ") " .
+             "VALUES('" . implode("', '", $fields_values) . "')");
+
+    // If appropriate, add contributor_type to tables.
+    if ($row[9] == 'contrib_widget') {
+      // Use field name without trailing 's' as initial guess for author type.
+      $auth_type = (substr($row[1], -1, 1) == 's') ? substr($row[1], 0, -1) : $row[1];
+      db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s')", $row[0], $auth_type);
+      db_query("INSERT INTO {biblio_contributor_type} (auth_category, biblio_type, auth_type) VALUES (%d, %d, %d)", $row[0], 0, $row[0]);
+    }
   }
-  else {
-    $result = array('success' => FALSE, 'query' => 'Could not open ' . $csv_file);
-  }
+  fclose($handle);
 
+  // @todo: Add comment explaining this non-obvious step about keys.
   if ($db_type == 'mysql' or $db_type == 'mysqli') {
     db_query("/*!40000 ALTER TABLE {biblio_field_type_data} ENABLE KEYS */;");
     db_query("/*!40000 ALTER TABLE {biblio_fields} ENABLE KEYS */;");
   }
+
+  $result = array('success' => TRUE, 'query' => 'Added field titles and default values');
   return $result;
 }
 
-function _add_custom_field_data() {
+/**
+ * Creates customized fields for bibliographic types based on a CSV data file.
+ *
+ * This function reads data from the CSV file biblio.field.type.data.csv and
+ * uses that information to create custom fields that can be used by various
+ * types of biblio content.
+ *
+ * @return array
+ *   An array of data summarizing attempts to add custom field data to tables
+ *   with the following keys:
+ *   - success: A boolean indicating success in this operation.
+ *   - query: A message string with further information about operation success.
+ */
+function _biblio_types_customize_fields() {
+  // Set the name of the CSV file with biblio field type mapping data.
+  $csv_file = drupal_get_path('module', 'biblio') . '/misc/biblio.field.type.data.csv';
 
-  $next_ctdid=10; //first contributor_type_data id
+  // Immediately return if handle to CSV file cannot be obtained.
+  if ($handle = fopen($csv_file, "r") === FALSE) {
+    $result = array('success' => FALSE, 'query' => 'Could not open CSV file ' . $csv_file);
+    return $result;
+  }
+
+  // Default for first contributor_type_data ID.
+  $next_ctdid = 10;
+
+  // Determine the column names defined in the {biblio_field_type_data} table.
   $schema = biblio_schema();
   $fieldnames = array_keys($schema['biblio_field_type_data']['fields']);
 
-  $query = "SELECT fid, name FROM {biblio_fields} ";
-  $res = db_query($query);
-  while ($row = db_fetch_object($res)){
-    $fieldmap[$row->name] =  $row->fid;
+  // Create array for mapping biblio field machine names to their field IDs.
+  $field_map = array();
+  $resource = db_query("SELECT fid, name FROM {biblio_fields}");
+  while ($row = db_fetch_object($resource)){
+    $field_map[$row->name] = $row->fid;
+  }
+
+  // Create array to map contributor field machine names to their field IDs.
+  $contributor_map = array();
+  $resource = db_query("SELECT fid, name FROM {biblio_fields} WHERE type = 'contrib_widget'");
+  while ($row = db_fetch_object($resource)) {
+    $contributor_map[$row->name] = $row->fid;
   }
 
-  $csv_file = drupal_get_path('module', 'biblio') .'/misc/biblio.field.type.data.csv';
+  // Build field ID map array to speed field customization process.
+  _biblio_field_id_by_name(NULL, NULL, NULL, array(
+    'tablename' => 'biblio_field_type_data',
+    'name_column' => 'title',
+    'id_column' => 'ftdid',
+  ));
+  _biblio_field_id_by_name(NULL, NULL, NULL, array(
+    'tablename' => 'biblio_contributor_type_data',
+    'name_column' => 'title',
+    'id_column' => 'auth_type',
+  ));
+
+  // First line of the CSV file contains the machine names of field types.
+  $header = fgetcsv($handle, 10000, ",");
+  // The second line has the default titles if none are set.
+  $generic = fgetcsv($handle, 10000, ",");
+
+  // Process all remaining rows in the CSV file.
+  while (($row = fgetcsv($handle, 10000, ",")) !== FALSE) {
+    $column = 0;
+    if (empty($row[1])) continue;
+
+    foreach ($header as $key => $field_name) {
+      if (!empty($field_name) && $field_name != 'tid') {
+        // @todo: Add comment about what this non-obvious condition this is for
+        if (!empty($row[$column]) && $row[$column] != "~" && isset($field_map[$field_name])) {
+          // Determine the value for ftdid field.
+          $ftd[0] = ($existing_id = _biblio_field_id_by_name('biblio_field_type_data', $row[$column]))
+                      ? $existing_id
+                      : variable_get('biblio_last_ftdid', 100);
+          // Determine the value for the title field.
+          $ftd[1] = trim($row[$column]);
+          // Default the value of the hint field to empty.
+          $ftd[2] = "";
+          $sql = "UPDATE {biblio_field_type} " .
+                 "SET ftdid = %d, cust_tdid = %d, visible = %d " .
+                 "WHERE tid = %d AND fid = %d ";
+          db_query($sql, $ftd[0], $ftd[0], 1, $row[1], $field_map[$field_name]);
+          if (!$existing_id) {
+            // If this title does not already exist, then insert it.
+            db_query("INSERT INTO {biblio_field_type_data} (" . implode(", ", $fieldnames) . ") " .
+                     "VALUES (%d, '%s', '%s')", $ftd);
+            // Cache the new ftd value for future use.
+            _biblio_field_id_by_name('biblio_field_type_data', $row[$column], $ftd[0]);
+            // Incrment by one the ID for field type data.
+            variable_set('biblio_last_ftdid', $ftd[0] + 1);
+          }
 
-  if ($handle = fopen($csv_file, "r")) {
-    $header = fgetcsv($handle, 10000, ","); // the first line has the field names
-    $generic = fgetcsv($handle, 10000, ","); // the second line has the default titles if none given
-    // build cache lookups
-    _id_by_name(NULL, NULL, NULL, array('tablename' => 'biblio_field_type_data', 'name_column' => 'title', 'id_column' => 'ftdid'));
-    _id_by_name(NULL, NULL, NULL, array('tablename' => 'biblio_contributor_type_data', 'name_column' => 'title', 'id_column' => 'auth_type'));
-    // map contributor field titles to field ids
-    $res = db_query("SELECT fid,name FROM {biblio_fields} WHERE type='contrib_widget'");
-    $contributor_categories = array();
-    while ($row = db_fetch_object($res)) {
-      $contributor_categories[$row->name] = $row->fid;
-    }
-    // process all rows of the file
-    while (($row = fgetcsv($handle, 10000, ",")) !== FALSE) {
-      $column = 0;
-      if (empty($row[1])) continue;
-
-      foreach ($header as $key => $field_name) {
-        if (!empty($field_name) && $field_name != 'tid') {
-          if (!empty($row[$column]) && $row[$column] != "~" && isset($fieldmap[$field_name])) {
-             $ftd[0] = ($existing_id = _id_by_name('biblio_field_type_data',$row[$column])) ? $existing_id : variable_get('biblio_last_ftdid', 100); // ftdid
-             $ftd[1] = trim($row[$column]);                    // title
-             $ftd[2] = "";                                     // hint
-             db_query("UPDATE {biblio_field_type}
-                      SET ftdid = %d, cust_tdid = %d, visible = %d
-                      WHERE tid = %d AND fid = %d ", $ftd[0], $ftd[0], 1, $row[1], $fieldmap[$field_name] );
-             if (!$existing_id){
-               // if this title doesn't alreay exist, then insert it into the table
-               db_query("INSERT INTO {biblio_field_type_data} (" . implode(", ", $fieldnames) . ")
-                        VALUES (%d, '%s', '%s')", $ftd);
-              _id_by_name('biblio_field_type_data',$row[$column], $ftd[0]);  // cache the new id value for future use
-              variable_set('biblio_last_ftdid', $ftd[0] +1); //increment the field type data id by one.
-             }
-
-             // also populate biblio_contributor_type tables
-             if ((substr($field_name,-7,7) == 'authors') && $row[$column] != '~' ) {
-               $type = $contributor_categories[$field_name];
-              $title = trim($row[$column]);
-              $biblio_type = $row[1];
-              $ctdid = ($eid = _id_by_name('biblio_contributor_type_data',$title)) ? $eid :  $next_ctdid;
-              db_query("UPDATE {biblio_contributor_type} SET auth_type=%d where auth_category=%d and biblio_type=%d", $ctdid, $type, $biblio_type);
-              if(!$eid) {
-                db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s')", $ctdid, $title);
-                _id_by_name('biblio_contributor_type_data',$title, $ctdid);  // cache the new id value for future use
-                $next_ctdid++;
-              }
-             }
-          } elseif ($row[$column] == "~" && isset($fieldmap[$field_name])) {
-            // turn the visibility off for this (~) type
-            db_query("UPDATE {biblio_field_type}
-                      SET visible = 0
-                      WHERE tid = %d AND fid = %d ", $row[1], $fieldmap[$field_name] );
-          } elseif (empty($row[$column]) && isset($fieldmap[$field_name])) {
-            // use the default field title when the title is blank
-            db_query("UPDATE {biblio_field_type}
-                      SET visible = 1
-                      WHERE tid = %d AND fid = %d ", $row[1], $fieldmap[$field_name] );
+          // Also populate contributor_type* tables.
+          if ((substr($field_name, -7, 7) == 'authors') && $row[$column] != '~') {
+            $type = $contributor_map[$field_name];
+            $title = trim($row[$column]);
+            $biblio_type = $row[1];
+            $ctdid = ($eid = _biblio_field_id_by_name('biblio_contributor_type_data', $title))
+                       ? $eid
+                       : $next_ctdid;
+            $sql = "UPDATE {biblio_contributor_type} SET auth_type=%d where auth_category=%d and biblio_type=%d";
+            db_query($sql, $ctdid, $type, $biblio_type);
+            if (!$eid) {
+              $sql = "INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s')";
+               db_query($sql, $ctdid, $title);
+               // Cache the new contributor_type_data value for future use.
+               _biblio_field_id_by_name('biblio_contributor_type_data', $title, $ctdid);
+               // Increment the contributor_data_type counter.
+               $next_ctdid++;
+            }
           }
         }
-        $column++;
+
+        // @todo: Add comment about what this non-obvious condition this is for
+        elseif ($row[$column] == "~" && isset($field_map[$field_name])) {
+          // Turn off the visibility for this (~) field type.
+          db_query("UPDATE {biblio_field_type}
+                    SET visible = 0
+                    WHERE tid = %d AND fid = %d ", $row[1], $field_map[$field_name]);
+        }
+
+        // If title is blank, update visibility using the defulat field title.
+        elseif (empty($row[$column]) && isset($field_map[$field_name])) {
+          db_query("UPDATE {biblio_field_type}
+                    SET visible = 1
+                    WHERE tid = %d AND fid = %d ", $row[1], $field_map[$field_name]);
+        }
       }
+      $column++;
     }
-    fclose($handle);
-    $result = array('success' => TRUE, 'query' => 'Added type specific field titles');
   }
-  else {
-    $result = array('success' => FALSE, 'query' => 'Could not open ' . $csv_file);
-  }
-
+  fclose($handle);
+  $result = array('success' => TRUE, 'query' => 'Added type specific field titles');
   return $result;
 }
-function _id_by_name($table, $name, $id = NULL, $build = NULL) {
-  static $result = NULL;
-  if (!empty($build)) { //refresh cache from table
-    unset($result[$build['tablename']]);
-    $res = db_query("SELECT ".$build['name_column'].", ".$build['id_column']." FROM {".$build['tablename']."}");
-    while ($row = db_fetch_array($res)){
-      $result[$build['tablename']][$row[$build['name_column']]] = $row[$build['id_column']];
+
+/**
+ * Maps CSV field data to table column names for fields in the biblio module.
+ *
+ * This function does what ...
+ *
+ * @param string $table
+ *   The name of the database table.
+ * @param string $csv_field
+ *   The name of the field in input data file.
+ * @param string $sql_field
+ *   (optional) Name of the sql field that maps to $csv_field.
+ * @param array $build
+ *   (optional) An associative array with the following keys:
+ *   - tablename: The name of the biblio table.
+ *   - name_column: The label for this field from the CSV file.
+ *   - id_column: The column name in SQL table for this field.
+ *
+ * return string|false
+ *
+ */
+function _biblio_field_id_by_name($table, $csv_field, $sql_field = NULL, $build = NULL) {
+  static $fields = NULL;
+
+  // Reset the static $fields variable with data from the database table.
+  if (!empty($build)) {
+    unset($fields[$build['tablename']]);
+    $sql = "SELECT " . $build['name_column']. ", " . $build['id_column'] . " " .
+           "FROM {" . $build['tablename'] . "}";
+    $resource = db_query($sql);
+    while ($row = db_fetch_array($resource)){
+      $fields[$build['tablename']][$row[$build['name_column']]] = $row[$build['id_column']];
     }
     return;
   }
-  $name = trim($name);
-  if (isset($result[$table][$name])) return $result[$table][$name];
-  if ($id) $result[$table][$name] = $id;
+  $name = trim($csv_field);
+  if (isset($fields[$table][$name])) {
+    return $fields[$table][$name];
+  }
+  if ($sql_field) {
+    $fields[$table][$name] = $sql_field;
+  }
   return FALSE;
 }
+
 /*
  * Removed updates 1 - 20 since they dated back to ver. 5-1.2
  */
 
+/**
+ * Update ...
+ */
 function biblio_update_21(){
   $result = array();
 
@@ -1427,6 +1635,9 @@ function biblio_update_21(){
   return $result;
 }
 
+/**
+ * Update ...
+ */
 function biblio_update_22() {
   global $db_type;
   $result = array();
@@ -1468,6 +1679,9 @@ function biblio_update_22() {
 
 }
 
+/**
+ * Update ...
+ */
 function biblio_update_23() {
   $result = array();
 
@@ -1477,6 +1691,9 @@ function biblio_update_23() {
 
 }
 
+/**
+ * Update ...
+ */
 function biblio_update_24() {
   $result = array();
 
@@ -1488,6 +1705,9 @@ function biblio_update_24() {
 
 }
 
+/**
+ * Update ...
+ */
 function biblio_update_25() {
   $result = array();
 
@@ -1496,6 +1716,9 @@ function biblio_update_25() {
   return $result;
 }
 
+/**
+ * Update ...
+ */
 function biblio_update_26() {
   $result = array();
 
@@ -1507,6 +1730,9 @@ function biblio_update_26() {
   return $result;
 }
 
+/**
+ * Update ...
+ */
 function biblio_update_27(){
   global $db_type;
   $result = array();
@@ -1520,8 +1746,10 @@ function biblio_update_27(){
   return $result;
 }
 
-
-function _move_field_data(&$result)
+/**
+ *
+ */
+function _biblio_move_field_data(&$result)
 {
   $schema = biblio_schema();
 
@@ -1579,11 +1807,14 @@ function _move_field_data(&$result)
   return $result;
 }
 /**
- * This function generates md5 hashes for all the biblio entries in the
- * database. These hashes are used to detect potential duplicate entries
- * when adding or importing.
+ * Generates md5 hash values for biblio content.
  *
- * @return a result array for the update process
+ * This function generates md5 hashes for all biblio content in the database.
+ * These hashes are NOT used for security purposes, but rather to detect
+ * potential duplicate entries when adding or importing new biblio content.
+ *
+ * @return array
+ *  A result array with two keys: 'success' and 'query'.
  */
 function biblio_md5_generate()
 {
@@ -1608,52 +1839,78 @@ function biblio_md5_generate()
 }
 
 /**
+ * Parses author name into components and populates array of name components.
+ *
  * This parses the old (pre 6.x) format author entry, splits in on
- * the semicolons and adds new elements to the biblio_contributors array
- * @param $biblio_contributors an array passed in by reference
- * @param $authors    The old author string
- * @param $type   The type of author (Primary, Secondary, Tertiary, Corporate)
- * @return none ($biblio_contributors is passed in by reference)
+ * the semicolons and adds new elements to the biblio_contributors array.
+ *
+ * @param array $biblio_contributors
+ *   An array passed in by reference.
+ * @param string $authors
+ *   The author string in pre-Drupal 6 format.
+ * @param integer $cat
+ *   (optional) The type of author (Primary, Secondary, Tertiary, Corporate) as
+ *   an integer ID.  The default is 1 (Primary).
  */
-function _parse_authors(&$biblio_contributors, $authors, $cat = 1)
-{
+function _biblio_parse_authors(&$biblio_contributors, $authors, $cat = 1) {
   $authors = str_ireplace(" and ", "; ", $authors);
   $authors = str_ireplace(" & ", "; ", $authors);
   $author_array = explode(';', $authors);
   $rank = 0;
-  foreach($author_array as $author)
-  {
-    // insert spaces after firstname initials if neccessary
+  foreach ($author_array as $author) {
+    // Insert spaces after firstname initials, if neccessary.
     $author = preg_replace("/\.([^\s-])/", ". \\1", trim($author));
     $biblio_contributors[$cat][] = array('name' => $author, 'auth_type' => $cat, 'rank' => $rank++);
   }
 }
 
-function _move_authors(&$result)
+/**
+ * Moves author data into biblio_contributor* tables.
+ *
+ * This function ...
+ *
+ * @return array
+ *   An associative array.
+ */
+function _biblio_move_authors(&$result)
 {
   $disable = FALSE;
-  if (!module_exists('biblio')) { // if the module is disabled, enable it so drupal_get_schema will work
+  // If the biblio module is disabled, enable it so drupal_get_schema will work.
+  if (!module_exists('biblio')) {
     module_enable(array('biblio'));
     $disable = TRUE;
   }
   drupal_get_schema('biblio_contributor', TRUE);
   drupal_get_schema('biblio_contributor_data', TRUE);
-  // this update will move author information from existing biblio table to the new
-  // biblio_contributor_data table and make the appropriate links in the biblio_contributor table
+
+  // Tthis update will move author information from existing {biblio} table to
+  // the new {biblio_contributor_data} table and create the appropriate cross-
+  // reference links in the {biblio_contributor) table.
   require_once(drupal_get_path('module', 'biblio') . '/includes/biblio.contributors.inc');
-  $res = db_query("SELECT nid,vid,biblio_authors, biblio_secondary_authors,biblio_tertiary_authors,biblio_corp_author FROM {biblio}  ");
-  $count=0; $count_success=0;
+  $res = db_query("SELECT nid,vid,biblio_authors, biblio_secondary_authors,biblio_tertiary_authors,biblio_corp_author FROM {biblio}");
+  $count = 0;
+  $count_success = 0;
   while ($biblio = db_fetch_array($res)) {
     $biblio_contributors = array();
-    if (!empty($biblio['biblio_authors'])) _parse_authors($biblio_contributors, $biblio['biblio_authors'], 1);
-    if (!empty($biblio['biblio_secondary_authors'])) _parse_authors($biblio_contributors, $biblio['biblio_secondary_authors'], 2);
-    if (!empty($biblio['biblio_tertiary_authors'])) _parse_authors($biblio_contributors, $biblio['biblio_tertiary_authors'], 3);
-    if (!empty($biblio['biblio_corp_author'])) _parse_authors($biblio_contributors, $biblio['biblio_corp_author'], 5);
+    if (!empty($biblio['biblio_authors'])) {
+       _biblio_parse_authors($biblio_contributors, $biblio['biblio_authors'], 1);
+    }
+    if (!empty($biblio['biblio_secondary_authors'])) {
+       _biblio_parse_authors($biblio_contributors, $biblio['biblio_secondary_authors'], 2);
+    }
+    if (!empty($biblio['biblio_tertiary_authors'])) {
+       _biblio_parse_authors($biblio_contributors, $biblio['biblio_tertiary_authors'], 3);
+    }
+    if (!empty($biblio['biblio_corp_author'])) {
+      _biblio_parse_authors($biblio_contributors, $biblio['biblio_corp_author'], 5);
+    }
     $biblio_contributors = biblio_parse_contributors($biblio_contributors);
-    if (_save_contributors($biblio_contributors, $biblio['nid'], $biblio['vid'])) $count_success++;
+    if (_biblio_save_contributors($biblio_contributors, $biblio['nid'], $biblio['vid'])) {
+       $count_success++;
+    }
     $count++;
   }
-  // change auth_type to match overrides set in old biblio_type_details
+  // Change auth_type to match overrides set in old biblio_type_details.
   update_sql("UPDATE {biblio_contributor} c
     /* augment by biblio_type from biblio */
     INNER JOIN {biblio} b ON c.nid=b.nid AND c.vid=b.vid
@@ -1672,32 +1929,49 @@ function _move_authors(&$result)
     /* update auth_type in biblio_contributor table */
     SET c.auth_type=ctd.auth_type");
   if ($count_success == $count) {
-    $mesg = 'Moved authors from '.$count_success.' / '.$count.' publications to the new database structure';
+    $message = 'Moved authors from ' . $count_success . ' / ' . $count . ' publications to the new database structure';
     $contributors = array(
       1 => 'biblio_authors',
       2 => 'biblio_secondary_authors',
       3 => 'biblio_tertiary_authors',
       4 => 'biblio_subsidiary_authors',
-      5 => 'biblio_corp_author');
-      // if the were sucessfully moved, remove obsolete D5 columns from biblio table (if they are present)
-      foreach($contributors as $column) {
-      if (db_column_exists('biblio', $column)) db_drop_field($result,'biblio', $column);
+      5 => 'biblio_corp_author',
+    );
+
+    // If the authors were sucessfully moved, remove obsolete D5 columns from
+    // {biblio} table (if they are still present).
+    foreach ($contributors as $column) {
+      if (db_column_exists('biblio', $column)) {
+        db_drop_field($result, 'biblio', $column);
+      }
     }
   }
   else {
     $count_fail = $count - $count_success;
-    $mesg = 'There was a problem moving authors from '. $count_fail .' / '. $count .' publications to the new database structure. The existing author fields have been retained in the database, go to the "admin/settings/biblio/author" page to try again.';
+    $message = 'There was a problem moving authors from ' . $count_fail . ' / ' . $count . 
+      ' publications to the new database structure. The existing author fields have been ' .
+      'retained in the database, go to the "admin/settings/biblio/author" page to try again.';
   }
-  $result[] = array('success' => ($count_success == $count),
-                    'query' => $mesg);
+  $result[] = array(
+    'success' => ($count_success == $count),
+    'query' => $message,
+  );
 
-  if ($disable) { // if the module was disabled, then set it back that way.
+  // If the biblio module started as disabled, then set it back to that state.
+  if ($disable) { 
     module_disable(array('biblio'));
   }
-
   return;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6000()
 {
   $result = array();
@@ -1730,13 +2004,13 @@ function biblio_update_6000()
   db_create_table($result, 'biblio_collection_type',$schema['biblio_collection_type']);
   db_create_table($result, 'biblio_duplicates',$schema['biblio_duplicates']);
 
-  // fill biblio_field* tables with defaults
-  $result[] = _add_db_field_data();
-  $result[] = _add_custom_field_data();
+  // Fill the biblio_field* tables with default definition records.
+  $result[] = _biblio_add_field_definitions();
+  $result[] = _biblio_types_customize_fields();
 
   // move data
-  _move_field_data($result);
-  _move_authors($result);
+  _biblio_move_field_data($result);
+  _biblio_move_authors($result);
 
   db_drop_table($result, 'biblio_fields_old');
   db_drop_table($result, 'biblio_type_details');
@@ -1745,6 +2019,14 @@ function biblio_update_6000()
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6011(){
   $result = array();
   $schema = biblio_schema();
@@ -1754,6 +2036,14 @@ function biblio_update_6011(){
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6013() {
   $result = array();
   if (!db_column_exists('biblio_contributor', 'auth_category')) { // we don't need to do this if upgrading from 5.x
@@ -1770,6 +2060,15 @@ function biblio_update_6013() {
   $result[] = update_sql("UPDATE {biblio_fields} SET maxsize=20 WHERE name='biblio_year'");
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6014() {
   $result = array();
   $contributors = array(
@@ -1813,6 +2112,15 @@ function biblio_update_6014() {
   // remove obsolete D5 columns from biblio table (if they are present)
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6015() {
   require_once(drupal_get_path('module', 'biblio') .'/includes/biblio.keywords.inc');
   $result = array();
@@ -1842,6 +2150,14 @@ function biblio_update_6015() {
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6016() {
   $result = array();
   $result[] = update_sql("ALTER TABLE {biblio}
@@ -1853,6 +2169,15 @@ function biblio_update_6016() {
                           MODIFY COLUMN biblio_doi                VARCHAR(255)");
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6017() {
   if (!db_column_exists('biblio_contributor_data', 'aka')) { // we don't need to do this if upgrading from 5.x
     $result = array();
@@ -1861,6 +2186,14 @@ function biblio_update_6017() {
   }
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6018() {
   $result = array();
   $result[] = update_sql("UPDATE {biblio_contributor_data} SET aka = cid WHERE aka = 0 OR aka IS NULL");
@@ -1872,12 +2205,30 @@ function biblio_update_6018() {
   if (db_table_exists('biblio_u5')) db_drop_table($result, 'biblio_u5');
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6019() {
   $result = array();
   $result[] = update_sql("UPDATE {biblio_fields} SET maxsize = 1000 WHERE name = 'biblio_keywords' ");
 
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6020() {// add new 'access biblio content' permission to any role which has 'access content'
   $result = array();
   $dbresult = db_query('SELECT p.* FROM {permission} p');
@@ -1889,6 +2240,15 @@ function biblio_update_6020() {// add new 'access biblio content' permission to
   }
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6021() {
   $result = array();
   db_change_field($result, 'biblio', 'biblio_number', 'biblio_number', array('type' => 'varchar', 'length' => '128'));
@@ -1904,6 +2264,15 @@ function biblio_update_6021() {
   db_change_field($result, 'biblio', 'biblio_issn', 'biblio_issn', array('type' => 'varchar', 'length' => '128'));
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6022() {
   $result = array();
   $result[] = update_sql("UPDATE {biblio_fields} SET maxsize = 128 WHERE name = 'biblio_number'
@@ -1919,8 +2288,15 @@ function biblio_update_6022() {
                           OR name = 'biblio_issn' ");
   return $result;
 }
-/* add the new field -refereed- on the biblio table
-*/
+
+/* 
+ * Update ...
+ *
+ * Add the new field -refereed- on the biblio table
+ *
+ * @return array
+ *   An array of associative arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6024() {
   $result = array();
 
@@ -1945,18 +2321,26 @@ function biblio_update_6024() {
    insert a tid,fid using the new fid for every available tid */
 
   $newsql = "SELECT DISTINCT tid FROM {biblio_field_type} ORDER BY tid DESC";
-
   $tidlist = db_query($newsql);
   while ($db_result = db_fetch_array($tidlist)) {
     $newtid = $db_result['tid'] ;
     db_query('INSERT INTO {biblio_field_type}
-       (tid, fid, ftdid, cust_tdid, common, autocomplete, required, weight, visible)
-        VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d)',
-    $newtid, $newfid, $newfid, $newfid, 1, 1, 0, 1, 1);
+      (tid, fid, ftdid, cust_tdid, common, autocomplete, required, weight, visible)
+       VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d)',
+       $newtid, $newfid, $newfid, $newfid, 1, 1, 0, 1, 1
+    );
   }
-
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6025() {
   $result = array();
   $schema = biblio_schema();
@@ -1964,12 +2348,21 @@ function biblio_update_6025() {
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6026() {
   $result = array();
-  // move custom block titles stored in variable "biblio_block_title" to the block table if the title has not already been overriden
+  // Move custom block titles stored in variable "biblio_block_title" to the 
+  // block table if the title has not already been overriden.
   $custom_title = variable_get('biblio_block_title', '');
   if (!empty($custom_title)) {
-    $db_result = db_query("SELECT bid,title FROM {blocks} b where module='biblio' ");
+    $db_result = db_query("SELECT bid,title FROM {blocks} b where module='biblio'");
     while ($block = db_fetch_object($db_result)) {
       if (empty ($block->title)) {
         $block->title = $custom_title;
@@ -1980,10 +2373,20 @@ function biblio_update_6026() {
   }
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6027() {
-  // renunmber the author rank such that it is zero based accross all categories
-  // this only needs to be done for entries that actually have auth_categories other than 1
-  require_once(drupal_get_path('module', 'biblio') .'/includes/biblio.contributors.inc');
+  // Renunmber the author rank such that it is zero based across all categories.
+  // This only needs to be performed on biblio entries that actually have 
+  // auth_categories other than 1.
+  require_once(drupal_get_path('module', 'biblio') . '/includes/biblio.contributors.inc');
   $result =  array();
   $count = 0;
   $db_result = db_query("SELECT DISTINCT(vid),nid FROM {biblio_contributor} WHERE auth_category IN (2,3,4,5) ");
@@ -1991,53 +2394,82 @@ function biblio_update_6027() {
   $count_success = db_result($db_count_result);
   while ($node = db_fetch_object($db_result)) {
     $contributors = biblio_load_contributors($node->vid);
-    _save_contributors($contributors, $node->nid, $node->vid, $update = FALSE) ;
+    _biblio_save_contributors($contributors, $node->nid, $node->vid, $update = FALSE);
     $count++;
   }
-  $mesg = "Reordered the authors on $count/$count_success nodes";
+  $message = "Reordered the authors on $count/$count_success nodes";
   $result[] = array('success' => ($count_success == $count),
-                    'query' => $mesg);
+                    'query' => $message);
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6028() {
-  $ret = array();
-
+  $result = array();
   $table = drupal_get_schema_unprocessed('system', 'cache');
   $table['description'] = 'Cache table for biblio to store pre-built csl objects';
   $table['fields']['serialized']['default'] = 1;
-
-  db_create_table($ret, 'cache_biblio_csl_object', $table);
-
-  return $ret;
+  db_create_table($result, 'cache_biblio_csl_object', $table);
+  return $resultt;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6029() {
   $result = array();
   $spec = array(
-        'type' => 'blob',
-        'not null' => FALSE,
-        'default'  => NULL,
-        'size' => 'big',
-        'description' => 'Stores the mapping between biblio fields and external file formats',
-        );
+    'type' => 'blob',
+    'not null' => FALSE,
+    'default'  => NULL,
+    'size' => 'big',
+    'description' => 'Stores the mapping between biblio fields and external file formats',
+  );
   db_add_field($result, 'biblio_type_maps', 'export_map', $spec);
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6030() {
   $result = array();
   $spec = array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default'  => 0,
-        'unsigned' => TRUE,
-        'description' => 'Determines if the author name is allowed to be reformated by the variaous styles or should be used literally.',
-        );
+    'type' => 'int',
+    'not null' => TRUE,
+    'default'  => 0,
+    'unsigned' => TRUE,
+    'description' => 'Determines if the author name is allowed to be reformated by the variaous styles or should be used literally.',
+  );
   db_add_field($result, 'biblio_contributor_data', 'literal', $spec);
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6031() {
   $result = array();
   $types[] = array(131,'Journal',NULL,3);
@@ -2047,33 +2479,49 @@ function biblio_update_6031() {
   $types[] = array(135,'Presentation',NULL,8);
   $types[] = array(136,'Newspaper',NULL,8);
 
-  foreach($types as $record)
-  {
+  foreach($types as $record) {
     $result[] = update_sql("INSERT INTO {biblio_types} (tid, name, description, weight) VALUES ('" . implode("', '", $record) . "')");
   }
-    $result[] = update_sql("DELETE FROM {biblio_types} WHERE tid=-1");
-
- return $result;
+  $result[] = update_sql("DELETE FROM {biblio_types} WHERE tid=-1");
+  return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6032() {
   $result = array();
-    $spec = array(
-        'type' => 'varchar',
-        'length' => '255',
-        'not null' => TRUE,
-        'default' => '',
-        'description' => 'Full name',
-        );
+  $spec = array(
+    'type' => 'varchar',
+    'length' => '255',
+    'not null' => TRUE,
+    'default' => '',
+    'description' => 'Full name',
+  );
   db_change_field($result, 'biblio_contributor_data', 'name', 'name', $spec);
   return $result;
 }
+
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6033() {
   $result = array();
   $spec = array(
-        'type' => 'varchar',
-        'not null' => FALSE,
-        'length' => '64',
-        'description' => 'A normalized version of the title, used for sorting on titles. (only first 64 characters saved)',
+    'type' => 'varchar',
+    'not null' => FALSE,
+    'length' => '64',
+    'description' => 'A normalized version of the title, used for sorting on titles. (only first 64 characters saved)',
   );
   db_add_field($result, 'biblio', 'biblio_sort_title', $spec);
   cache_clear_all();
@@ -2081,8 +2529,16 @@ function biblio_update_6033() {
 }
 
 /**
+ * Update ...
+ *
  * Populates the  new "biblio_sort_title" column, which is used for title sorting.
-*/
+ *
+ * @param $sandbox
+ *
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6034(&$sandbox) {
  $ret = array();
   module_load_include('inc', 'biblio', '/includes/biblio.util');
@@ -2107,10 +2563,19 @@ function biblio_update_6034(&$sandbox) {
   return $ret;
 }
 
+/**
+ *
+ *
+ * @param $range
+ *   
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function _biblio_update_field_link_data($range){
   $result = array();
   $schema = biblio_schema();
-  $field_type_fieldnames = array_keys($schema['biblio_field_type']['fields']);
+  $field_type_columns = array_keys($schema['biblio_field_type']['fields']);
 
   $csv_file = drupal_get_path('module', 'biblio') .'/misc/biblio.field.link.data.csv';
 
@@ -2119,58 +2584,87 @@ function _biblio_update_field_link_data($range){
     while (($row = fgetcsv($handle, 10000, ",")) !== FALSE) {
       $column = 0;
       // add link data for default biblio type (0) and all other defined types (100-130)
-      foreach (range($range[0],$range[1]) as $t) {
-        $link_data = array($t,$row[0],$row[0],$row[0],$row[3],$row[4],$row[5],$row[6],$row[7]);
-        $result[] = update_sql("INSERT INTO {biblio_field_type} (". implode(", ", $field_type_fieldnames) . ")
-                  VALUES ('" . implode("', '", $link_data) . "')");
+      foreach (range($range[0], $range[1]) as $t) {
+        $field_type_values = array($t,$row[0],$row[0],$row[0],$row[3],$row[4],$row[5],$row[6],$row[7]);
+        $result[] = update_sql("INSERT INTO {biblio_field_type} (". implode(", ", $field_type_columns) . ") " .
+                               "VALUES ('" . implode("', '", $field_type_values) . "')");
       }
     }
   }
   return $result;
 }
-function biblio_update_6035() {
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
+function biblio_update_6035() {
   $result = _biblio_update_field_link_data(array(131, 136));
   cache_clear_all();
   return $result;
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6036() {
   $result = array();
   $spec =  array(
-        'type' => 'varchar',
-        'not null' => FALSE,
-        'length' => '64',
-        'description' => '',
+    'type' => 'varchar',
+    'not null' => FALSE,
+    'length' => '64',
+    'description' => '',
   );
   db_change_field($result, 'biblio', 'biblio_date', 'biblio_date', $spec);
   return $result;
 
 }
 
+/**
+ * Update ...
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
+ */
 function biblio_update_6037() {
   $result = array();
   $spec =  array(
-            'type' => 'blob',
-            'not null' => FALSE,
-            'description' => '',
-            'serialize' => TRUE,
-    );
+    'type' => 'blob',
+    'not null' => FALSE,
+    'description' => '',
+    'serialize' => TRUE,
+  );
   db_add_field($result, 'biblio', 'biblio_formats', $spec);
   return $result;
 }
+
 /**
- *
  * Widen the biblio_contributor_data.lastname column to 255 characters
+ *
+ * This update function ...
+ *
+ * @return array
+ *   An array of associaive arrays with 'success' and 'query' keys.
  */
 function biblio_update_6038() {
   $result = array();
   $spec =  array(
-      'type' => 'varchar',
-      'length' => '255',
-      'not null' => TRUE,
-      'default' => '',
-      'description' => 'Author last name',
+    'type' => 'varchar',
+    'length' => '255',
+    'not null' => TRUE,
+    'default' => '',
+    'description' => 'Author last name',
   );
   db_change_field($result, 'biblio_contributor_data', 'lastname', 'lastname', $spec);
   return $result;
diff --git a/biblio.module b/biblio.module
index 4a22901..c8e617d 100644
--- a/biblio.module
+++ b/biblio.module
@@ -3,33 +3,32 @@
  * @file
  * Main file for Drupal module biblio.
  *
- * Copyright (C) 2006-2012  Ron Jerome
- *
+ * // @todo: Explain briefly what the biblio module does...
  *
-
-
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * Copyright (C) 2006-2012  Ron Jerome
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
  *
- *   You should have received a copy of the GNU General Public License along
- *   with this program; if not, write to the Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
  *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
+
 define('BIBLIO_VERSION', '6.x-2.x-dev');
 
 /**
  * Retrieves author types based upon author category and biblio type.
  *
- * @param string $auth_category
- *   A string representing the category of author.
+ * @param ?? $auth_category
+ *   The category of author.
  * @param string $biblio_type
  *   A string representing the type of biblio item.
  *
@@ -49,7 +48,9 @@ function _biblio_get_auth_types($auth_category, $biblio_type) {
             ? $auth_types[$auth_category][$biblio_type]
             : NULL;
   // Fall back to defaults if no author types are defined for this biblio_type.
-  if (empty($result)) $result = $auth_types[$auth_category][0];
+  if (empty($result)) {
+    $result = $auth_types[$auth_category][0];
+  }
   return $result;
 }
 
@@ -389,9 +390,9 @@ function biblio_theme() {
 function biblio_autocomplete($field, $string = '') {
   $matches = array();
   if ($field == 'contributor') {
-  	$sql = "SELECT * FROM {biblio_contributor_data} " .
-  	       "WHERE LOWER(lastname) LIKE LOWER('%s%%') OR LOWER(firstname) LIKE LOWER('%s%%') " .
-  	       "ORDER BY lastname ASC ";
+    $sql = "SELECT * FROM {biblio_contributor_data} " .
+           "WHERE LOWER(lastname) LIKE LOWER('%s%%') OR LOWER(firstname) LIKE LOWER('%s%%') " .
+           "ORDER BY lastname ASC ";
     $result = db_query_range($sql, array($string, $string), 0, 10);
     while ($data = db_fetch_object($result)) {
       $matches[$data->name] = check_plain($data->name);
@@ -415,7 +416,7 @@ function biblio_autocomplete($field, $string = '') {
     }
   }
   else {
-  	$sql = "SELECT %s FROM {biblio} WHERE LOWER(%s) LIKE LOWER('%s%%') ORDER BY %s ASC";
+    $sql = "SELECT %s FROM {biblio} WHERE LOWER(%s) LIKE LOWER('%s%%') ORDER BY %s ASC";
     $result = db_query_range($sql, array($field, $field, $string, $field), 0, 10);
     while ($data = db_fetch_object($result)) {
       $matches[$data-> $field] = check_plain($data-> $field);
@@ -465,68 +466,86 @@ function biblio_help($path, $arg) {
   switch ($path) {
     case 'admin/help#biblio' :
       return biblio_help_page();
+
     case 'admin/modules#description' :
       // This description is shown in the listing at admin/modules.
       return t('Manages a list of scholarly papers on your site');
+
     case 'node/add#biblio' :
-      // This description shows up when users click "create content."
+      // This description appears when users click "create content."
       return t('This allows you to add a bibliographic entry to the database');
   }
 }
+
+/**
+ * Implements hook_node_info().
+ */
 function biblio_node_info() {
   return array(
     'biblio' => array(
       'name' => t('Biblio'),
       'module' => 'biblio',
       'description' => t('Manages bibliographies')
-  )
+    )
   );
 }
+
 /**
- * Implementation of hook_access().
+ * Implements hook_access().
  *
- * Node modules may implement node_access() to determine the operations
- * users may perform on nodes. This example uses a very common access pattern.
+ * Node modules may implement node_access() to determine the operations users
+ * may perform on nodes. This example uses a very common access pattern.
  */
 function biblio_access($op, $node = '', $user = '') {
   switch ($op) {
     case 'create':
       return user_access('create biblio');
+
     case 'delete':
     case 'update':
       if (user_access('edit all biblio entries')) return TRUE;
       if (!isset($user->uid)) return;
       if (user_access('edit own biblio entries') && $user->uid == $node->uid) return TRUE;
       break;
+
     case 'view':
       if ((variable_get('biblio_view_only_own', 0)) && $user->uid != $node->uid) return FALSE;
       break;
+
     case 'admin':
       return user_access('administer biblio');
+
     case 'import':
       return user_access('import from file');
+
     case 'export':
       return user_access('show export links');
+
     case 'edit_author':
         if (user_access('administer biblio') || user_access('edit biblio authors')) return TRUE;
         break;
+
     case 'download':
       if (user_access('show download links')) return TRUE;
       if (!isset($user->uid)) return;
       if (user_access('show own download links') && ($user->uid == $node->uid)) return TRUE;
       break;
+
     case 'rss':
       return variable_get('biblio_rss', 0);
+
     default:
+      break;
   }
   return;
 }
+
 /**
- * Implementation of hook_perm().
+ * Implements of hook_perm().
  *
- * Since we are limiting the ability to create new nodes to certain users,
- * we need to define what those permissions are here. We also define a permission
- * to allow users to edit the nodes they created.
+ * Since we are restricting users in various ways when they wish to create,
+ * view, update and/or delete biblio content, we need to define what those
+ * permissions are here.
  */
 function biblio_perm() {
   return array(
@@ -567,7 +586,7 @@ function biblio_link($type, $node = NULL, $teaser = FALSE) {
     if (biblio_access('export', $node)) {
       $show_link = variable_get('biblio_lookup_links', array('google' => TRUE));
       if ($show_link['google']) {
-      	$links['biblio_google_scholar'] = theme('google_scholar_link', $node);
+        $links['biblio_google_scholar'] = theme('google_scholar_link', $node);
       }
     }
   }
@@ -1166,35 +1185,61 @@ function biblio_menu() {
   );
   return $items;
 }
+
+/**
+ * Implements hook_filter_clear()
+ */
 function biblio_filter_clear() {
   $options = '';
   $_SESSION['biblio_filter'] = array();
   $base = variable_get('biblio_base', 'biblio');
   if (isset($_GET['sort'])) {
-    $options .= "sort=". $_GET['sort'];
+    $options .= "sort=" . $_GET['sort'];
   }
   if (isset($_GET['order'])) {
     $options .= $options['query'] ? "&" : "";
-    $options .= "order=". $_GET['order'];
+    $options .= "order=" . $_GET['order'];
   }
   drupal_goto($base, $options);
 }
+
+/**
+ * Removes curly braces from a string.
+ *
+ * @param string $title_string
+ *   The text string to remove curly braces from.
+ *
+ * @return string
+ *   The resulting string with curly braces removed.
+ */
 function biblio_remove_brace($title_string){
-    //$title_string = utf8_encode($title_string);
-    $matchpattern = '/\{\$(?:(?!\$\}).)*\$\}|(\{[^}]*\})/';
-    $output = preg_replace_callback($matchpattern,'biblio_remove_brace_callback',$title_string);
-    return $output;
+  //$title_string = utf8_encode($title_string);
+  $matchpattern = '/\{\$(?:(?!\$\}).)*\$\}|(\{[^}]*\})/';
+  $output = preg_replace_callback($matchpattern,'biblio_remove_brace_callback',$title_string);
+  return $output;
 }
 
-function biblio_remove_brace_callback($match){
-        if(isset($match[1])){
-                $braceless = str_replace('{', '', $match[1]);
-                $braceless = str_replace('}', '', $braceless);
-                return $braceless;
-        }
-        return $match[0];
+/**
+ * Assists in the removal of curly braces with preg_replace_callback().
+ *
+ * @param array $match
+ *
+ *
+ * @return string
+ *
+ */
+function biblio_remove_brace_callback($match) {
+  if (isset($match[1])) {
+    $braceless = str_replace('{', '', $match[1]);
+    $braceless = str_replace('}', '', $braceless);
+    return $braceless;
+  }
+  return $match[0];
 }
-
+ 
+/**
+ * Implements hook_nodeapi().
+ */
 function biblio_nodeapi(& $node, $op, $a3, $a4) {
   if ($node->type == 'biblio') {
     switch ($op) {
@@ -1251,8 +1296,8 @@ function biblio_nodeapi(& $node, $op, $a3, $a4) {
  */
 function biblio_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == "biblio_node_form") {
-  	// For the first display of the biblio node form, this section removes all
-  	// the form elements execpt the publication type select box.
+    // For the first display of the biblio node form, this section removes all
+    // the form elements execpt the publication type select box.
     if (!isset($form_state['values']['biblio_type']) &&
         empty($form_state['post']['biblio_type']) &&
         empty($form_state['submitted']) &&
@@ -1781,7 +1826,7 @@ function _biblio_text_year($year) {
 }
 
 /**
- * Prepares a biblio node for submit to database. 
+ * Prepares a biblio node for submit to database.
  *
  * This function contains code common to both insert and update operations.
  *
@@ -1929,7 +1974,7 @@ function biblio_view(&$node, $teaser = FALSE, $page = FALSE) {
       case 'ft' :
         $node->content['body']['#value'] = theme('biblio_long', $node, $base, $style);
         break;
-        
+
       case 'tabular' :
       default :
         $node->content['body']['#value'] = theme('biblio_tabular', $node, $base, $teaser);
@@ -2138,19 +2183,19 @@ function biblio_filter($op, $delta = 0, $format = -1, $text = '') {
         // filter tips which are shown in the content editing interface.
         case 'description' :
           return t('Use &lt;bib&gt;citekey&lt;/bib&gt; or [bib]citebkey[/bib]to insert automatically numbered references.');
-        
+
         // We don't need the "prepare" operation for this filter, but it's required
         // to at least return the input text as-is.
         //TODO: May need to escape <fn> if we use HTML filter too, but Footnotes could be first
         case 'prepare' :
           return $text;
-     
+
         // The actual filtering is performed here. The supplied text should be
         // returned, once any necessary substitutions have taken place.
         case 'process' :
           $pattern = array('|\[bib](.*?)\[/bib]|s', '|<bib>(.*?)</bib>|s');
           // This is used with footnote module integration to replace the <bib> tags with <fn> tags
-          if (variable_get('biblio_footnotes_integration', 0) && module_exists('footnotes')) { 
+          if (variable_get('biblio_footnotes_integration', 0) && module_exists('footnotes')) {
             $text = preg_replace_callback($pattern, '_biblio_filter_footnote_callback', $text);
             return $text;
           }
@@ -2171,7 +2216,7 @@ function biblio_filter($op, $delta = 0, $format = -1, $text = '') {
           }
       }
       break;
-      
+
     case 1 :
       switch ($op) {
         // This description is shown in the administrative interface, unlike the
@@ -2290,7 +2335,7 @@ function biblio_term_path($term) {
     return ("$base/term_id/$term->tid");
   }
   else {
-  	return;
+    return;
   }
 }
 
@@ -2469,7 +2514,7 @@ function biblio_fix_isi_links(&$node) {
 
 /**
  *
- 
+
  * @return array
  *   An array of allowed HTML tags as values in array.
  *
@@ -2514,7 +2559,7 @@ function biblio_get_title_url_info($node, $base = NULL, $inline = FALSE) {
  *
  *
  * @param string $type
- *   Possible values include  (can be one of "type_names", "type_map" or "field_map") 
+ *   Possible values include  (can be one of "type_names", "type_map" or "field_map")
  * @param string $format
  *   keys like (tagged, ris, endnote_xml8 etc...)
  *
@@ -2544,7 +2589,7 @@ function biblio_set_map($type, $format, $map) {
 
 /**
  * Implemnts hook_reset_map().
- * 
+ *
  * @param string $type
  *
  * @param string $format
@@ -2558,7 +2603,7 @@ function biblio_reset_map($type, $format) {
  *
  *
  * @param object $node
- *   A node object (passed by reference) with populated with biblio type.
+ *   A node object (passed by reference) populated with biblio type.
  */
 function _biblio_export_visibility(&$node) {
   static $visibility = array();
@@ -2584,7 +2629,7 @@ function _biblio_export_visibility(&$node) {
  *
  *
  * @param string $type_name
- *   
+ *
  *
  * @return array
  *   An array of definitions for extra fields defined in teh biblio module.
diff --git a/includes/biblio.admin.inc b/includes/biblio.admin.inc
index 4b0b414..ae8da79 100644
--- a/includes/biblio.admin.inc
+++ b/includes/biblio.admin.inc
@@ -1,8 +1,13 @@
 <?php
 /**
- *   biblio.admin.inc
+ * @file
+ * Administrative files for the biblio module.
  *
- *   Copyright (C) 2006-2008  Ron Jerome
+ * This file contains various functions related to the administration of the
+ * biblio module.  These include user interface functions and others that are
+ * only needed by users with the 'administer biblio permission.
+ *
+ * Copyright (C) 2006-2012  Ron Jerome
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -17,35 +22,43 @@
  *   You should have received a copy of the GNU General Public License along
  *   with this program; if not, write to the Free Software Foundation, Inc.,
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
+
 /**
  * Default page callback for batches.
+ *
+ * @todo: Is this function still needed?
+ *
  */
-
 function biblio_admin_ahah($form, $element, $value) {
   switch ($form) {
 
   }
 }
-function biblio_admin_dir_layout_check() {
 
-    $dir = drupal_get_path('module', 'biblio');
-    $files = file_scan_directory($dir, '..*.inc$',  array('.', '..'), 0, FALSE);
+/**
+ * Checks on structure of include files for biblio module.
+ */
+function biblio_admin_dir_layout_check() {
+  $dir = drupal_get_path('module', 'biblio');
+  $files = file_scan_directory($dir, '..*.inc$',  array('.', '..'), 0, FALSE);
   if (count($files)) {
     $message = t('There is a problem with your Biblio installation! There should not be any ".inc" files in the %biblio directory.  You probably forgot to delete the old biblio files when you upgraded the module.  You should remove the following files from that directory...', array('%biblio' => $dir));
     $message .= "<ul>";
     foreach ($files as $file) {
-      $message .= "<li>" . $file->basename;
+      $message .= "<li>" . $file->basename . "</li>";
     }
     $message .= "</ul>";
     drupal_set_message($message, 'error');
+    // @todo: Log this list to the watchdog table as well?
   }
-
 }
+
 /**
-* Implementation of hook_settings().
-*/
+ * Implements hook_settings().
+ *
+ * @see biblio_admin_settings_form_submit()
+ */
 function biblio_admin_settings() {
   biblio_admin_dir_layout_check();
   $version = theme('advanced_help_topic','biblio','about-admin');
@@ -469,9 +482,9 @@ function biblio_admin_settings() {
     '#default_value' => variable_get('biblio_author_link_profile_path', 'user/[uid]'),
     '#description' => t('Do not include a leading "/"')
   );
-  $form['links']['author']['token_tree'] = array(
-      '#value' => theme('token_tree', array('all')),
-  );
+  $form['links']['author']['token_tree'] = array(
+      '#value' => theme('token_tree', array('all')),
+  );
 
   $form['openurl'] = array(
     '#type' => 'fieldset',
@@ -710,6 +723,10 @@ function biblio_admin_settings() {
   // and the menu will be rebuilt correctly.
   return ($form);
 }
+
+/**
+ * Submission function for the admin_settings_form().
+ */
 function biblio_admin_settings_form_submit($form, $form_state) {
   if ($form_state['values']['biblio_keyword_freetagging'] && $form_state['values']['biblio_keyword_vocabulary']) {
     if ($vocabulary = taxonomy_vocabulary_load(variable_get('biblio_keyword_vocabulary', 0))) {
@@ -718,13 +735,19 @@ function biblio_admin_settings_form_submit($form, $form_state) {
       taxonomy_save_vocabulary($vocabulary);
     }
   }
-  if( ($form['#biblio_base'] != $form_state['values']['biblio_base']) ||
-      ($form['#biblio_show_profile'] != $form_state['values']['biblio_show_profile']) ||
-      ($form['#biblio_my_pubs_menu'] != $form_state['values']['biblio_my_pubs_menu']) )
-  {
+  if ( ($form['#biblio_base'] != $form_state['values']['biblio_base'])
+    || ($form['#biblio_show_profile'] != $form_state['values']['biblio_show_profile']) 
+    || ($form['#biblio_my_pubs_menu'] != $form_state['values']['biblio_my_pubs_menu']) 
+     ) {
     menu_rebuild();
   }
 }
+
+/**
+ *
+ 
+ * @see biblio_admin_types_edit_form_submit()
+ */
 function biblio_admin_types_edit_form() {
   $tid = 0;
   $arg_list = func_get_args();
@@ -896,7 +919,10 @@ function biblio_admin_types_edit_form() {
   return $form;
 }
 
-function biblio_admin_types_edit_form_submit($form, & $form_state) {
+/**
+ *
+ */
+function biblio_admin_types_edit_form_submit($form, &$form_state) {
   $tid = $form_state['values']['type_id'];
   if (empty($tid)) $tid = 0;
 
@@ -994,6 +1020,9 @@ function biblio_admin_types_edit_form_submit($form, & $form_state) {
   biblio_locale_refresh_fields($tid);
 }
 
+/**
+ *
+ */
 function biblio_admin_io_mapper_page() {
   $formats = module_invoke_all('biblio_mapper_options');
   asort($formats);
@@ -1055,6 +1084,11 @@ function biblio_admin_io_mapper_form($form_state, $format, $exportable = TRUE) {
   return $form;
 }
 
+/**
+ *
+ *
+ * @see biblio_admin_io_mapper_form()
+ */
 function theme_biblio_admin_io_mapper_form($form) {
   $header = $rows = array();
   $output = drupal_render($form['title']);
@@ -1067,6 +1101,11 @@ function theme_biblio_admin_io_mapper_form($form) {
   return $output;
 }
 
+/**
+ *
+ *
+ *
+ */
 function biblio_admin_io_mapper_add_form($form_state, $format, $type) {
   $formats = module_invoke_all('biblio_mapper_options');
 
@@ -1107,6 +1146,12 @@ function biblio_admin_io_mapper_add_form($form_state, $format, $type) {
   return $form;
 }
 
+/**
+ *
+ *
+ *
+ * @see biblio_admin_io_mapper_add_form()
+ */
 function theme_biblio_admin_io_mapper_add_form($form) {
   $output = '';
   $title = $form['fileformat_title']['#value'];
@@ -1118,6 +1163,11 @@ function theme_biblio_admin_io_mapper_add_form($form) {
   return $output;
 }
 
+/**
+ *
+ *
+ *
+ */
 function biblio_admin_io_mapper_add_form_pubtype_submit($form, &$form_state) {
   $names = biblio_get_map('type_names', $form_state['values']['fileformat']);
   $names[$form_state['values']['type_name']] = $form_state['values']['type_desc'];
@@ -1125,12 +1175,23 @@ function biblio_admin_io_mapper_add_form_pubtype_submit($form, &$form_state) {
   $form_state['redirect'] = 'admin/settings/biblio/iomap/edit/' . $form_state['values']['fileformat'];
 }
 
+/**
+ *
+ *
+ *
+ */
 function biblio_admin_io_mapper_add_form_field_submit($form, &$form_state) {
   $names = biblio_get_map('field_map', $form_state['values']['fileformat']);
   $names[$form_state['values']['type_name']] = '';
   biblio_set_map('field_map', $form_state['values']['fileformat'], $names);
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_type_mapper_form($format = 'bibtex') {
   $formats = module_invoke_all('biblio_mapper_options');
   $form['#file_format_title'] = isset($formats[$format]) ? $formats[$format]['title'] : '';
@@ -1173,10 +1234,16 @@ function biblio_admin_type_mapper_form($format = 'bibtex') {
   return $form;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function theme_biblio_admin_type_mapper_form($form) {
   $title = $form['#file_format_title'];
 
-   foreach (element_children($form['type']) as $key ) {
+  foreach (element_children($form['type']) as $key ) {
     $rows[] = array(
     drupal_render($form['type'][$key]['format']),
     drupal_render($form['type'][$key])
@@ -1201,6 +1268,12 @@ function theme_biblio_admin_type_mapper_form($form) {
   return $output;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_type_mapper_form_submit($form, $form_state) {
   foreach($form_state['values']['typemap']['type'] as $key => $value) {
     if (is_array($value)) {
@@ -1210,11 +1283,23 @@ function biblio_admin_type_mapper_form_submit($form, $form_state) {
   biblio_set_map('type_map', $form_state['values']['fileformat'], $map);
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_type_mapper_form_reset_submit($form, $form_state) {
   biblio_reset_map('type_map', $form_state['values']['fileformat']);
   biblio_reset_map('type_names', $form_state['values']['fileformat']);
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_field_mapper_form($format = 'bibtex', $exportable = TRUE) {
   $formats = module_invoke_all('biblio_mapper_options');
   $form['#file_format_title'] = isset($formats[$format]) ? $formats[$format]['title'] : '';
@@ -1262,6 +1347,12 @@ function biblio_admin_field_mapper_form($format = 'bibtex', $exportable = TRUE)
   return $form;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function theme_biblio_admin_field_mapper_form($form) {
 
   $title = $form['#file_format_title'];
@@ -1287,6 +1378,12 @@ function theme_biblio_admin_field_mapper_form($form) {
   return $output;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_field_mapper_form_submit($form, $form_state) {
   foreach ($form_state['values']['fieldmap']['type'] as $key => $value) {
     if (is_array($value)) {
@@ -1302,11 +1399,23 @@ function biblio_admin_field_mapper_form_submit($form, $form_state) {
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_field_mapper_form_reset_submit($form, $form_state) {
   biblio_reset_map('field_map', $form_state['values']['fileformat']);
   biblio_reset_map('export_map', $form_state['values']['fileformat']);
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_form() {
   $output = '';
   $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid > 0');
@@ -1341,6 +1450,13 @@ function biblio_admin_types_form() {
   $output .= ' [ '. l(t('Reset all types to defaults'), 'admin/settings/biblio/fields/type/reset') .' ]';
   return $output;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_add_form() {
   $form['name'] = array(
     '#type' => 'textfield',
@@ -1364,7 +1480,14 @@ function biblio_admin_types_add_form() {
   );
   return $form;
 }
-function biblio_admin_types_add_form_submit($form, & $form_state) {
+
+/**
+ *
+ *
+ *
+ *
+ */
+function biblio_admin_types_add_form_submit($form, &$form_state) {
   $values = $form_state['values'];
   $values['tid'] = variable_get('biblio_max_user_tid', '999') + 1;
   drupal_write_record('biblio_types', $values);
@@ -1396,6 +1519,13 @@ function biblio_admin_types_add_form_submit($form, & $form_state) {
 
   drupal_goto('admin/settings/biblio/fields/type');
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_hide() {
   $args = func_get_args();
   if ($args[0] > 0 && is_numeric($args[0])) {
@@ -1403,6 +1533,13 @@ function biblio_admin_types_hide() {
   }
   drupal_goto('admin/settings/biblio/fields/type');
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_show() {
   $args = func_get_args();
   if ($args[0] > 0 && is_numeric($args[0])) {
@@ -1410,6 +1547,13 @@ function biblio_admin_types_show() {
   }
   drupal_goto('admin/settings/biblio/fields/type');
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_delete_form() {
   $args = func_get_args();
   if ($args[1] > 0 && is_numeric($args[1])) {
@@ -1434,11 +1578,25 @@ function biblio_admin_types_delete_form() {
     drupal_goto('admin/settings/biblio/fields/type');
   }
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_delete_form_submit($form, & $form_state) {
   db_query('DELETE FROM {biblio_types} WHERE tid = %d', $form_state['values']['tid']);
   db_query('DELETE FROM {biblio_field_type} WHERE tid = %d', $form_state['values']['tid']);
   drupal_goto('admin/settings/biblio/fields/type');
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_reset_form() {
   $form['reset'] = array(
     '#type' => 'value',
@@ -1447,11 +1605,19 @@ function biblio_admin_types_reset_form() {
   $output = confirm_form($form, t('Are you sure you want to reset ALL the field definitions to the defaults? '), $_GET['destination'] ? $_GET['destination'] : 'admin/settings/biblio/fields/type', t('By doing this, you will loose all customizations you have made to the field titles, <b><u>this action cannot be undone</u></b>!'), t('Reset!'), t('Cancel'));
   return $output;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_types_reset_form_submit($form, & $form_state) {
   module_load_include('install', 'biblio');
   biblio_reset_types();
   drupal_goto("admin/settings/biblio/fields/type");
 }
+
 /*
  * This functin is used by both the admin/settings/biblio page and user profile page
  *   - if $user is set, then it is being called from the user profile page
@@ -1549,6 +1715,13 @@ function _biblio_get_user_profile_form(& $form, $profile_user = FALSE) {
 
   }
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function _biblio_get_user_doi_form(&$form, $user) {
   $form['biblio_doi'] = array(
     '#type' => 'fieldset',
@@ -1567,6 +1740,13 @@ function _biblio_get_user_doi_form(&$form, $user) {
   );
   return $form;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function _biblio_get_user_openurl_form(&$form, $user) {
   $form['openurl'] = array(
     '#type' => 'fieldset',
@@ -1592,6 +1772,7 @@ function _biblio_get_user_openurl_form(&$form, $user) {
   );
   return $form;
 }
+
 /*  This function parses the module directory for 'style' files, loads them and
  *  calls the info fuction to get some basic information like the short and long
  *  names of the style
@@ -1604,6 +1785,13 @@ function biblio_form_sort($a, $b) {
   }
   return ($a_weight < $b_weight) ? -1 : 1;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_get_query($name) {
   switch ($name) {
     case "author_dup" :
@@ -1619,7 +1807,12 @@ function biblio_admin_get_query($name) {
   }
 }
 
-
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_types_form($form_state, $op = NULL, $id = NULL) {
   switch ($op) {
     case 'edit':
@@ -1661,6 +1854,12 @@ function biblio_admin_author_types_form($form_state, $op = NULL, $id = NULL) {
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function theme_biblio_admin_author_types_form($form) {
   // We need this complex query to realize author_types which are not in use (cid is NULL)
   $db_result = db_query("SELECT ctd.*, cid FROM {biblio_contributor_type_data} ctd
@@ -1693,6 +1892,12 @@ function theme_biblio_admin_author_types_form($form) {
   return $output;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_types_form_submit($form, $form_state) {
 
   $record->title = $form_state['values']['title'];
@@ -1711,6 +1916,13 @@ function biblio_admin_author_types_form_submit($form, $form_state) {
 
   }
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_type_delete_confirm(&$form_state, $type_id) {
   $base = variable_get('biblio_base', 'biblio');
   $type_data = db_fetch_object(db_query('SELECT * FROM {biblio_contributor_type_data} bctd WHERE bctd.auth_type = %d ', $type_id));
@@ -1728,6 +1940,13 @@ function biblio_admin_author_type_delete_confirm(&$form_state, $type_id) {
   );
 
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_type_delete_confirm_submit($form, &$form_state) {
 
   db_query("DELETE FROM {biblio_contributor_type_data} WHERE auth_type=%d", $form_state['values']['auth_type']);
@@ -1736,6 +1955,12 @@ function biblio_admin_author_type_delete_confirm_submit($form, &$form_state) {
   drupal_goto('admin/settings/biblio/author/type');
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_edit_form($form_state, $author_id) {
   $merge_options = $linked = array();
   $author = db_fetch_object(db_query('SELECT * FROM {biblio_contributor_data} b WHERE b.cid = %d ', $author_id));
@@ -1918,12 +2143,24 @@ function biblio_admin_author_edit_form($form_state, $author_id) {
   return $form;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_edit_form_validate($form, &$form_state) {
   foreach ($form_state['values'] as $key => $value) {
     if (is_string($value)) $form_state['values'][$key] = trim($value);
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_author_edit_form_submit($form, &$form_state) {
   module_load_include('inc', 'biblio', 'includes/biblio.contributors');
   $op = $form_state['values']['op'];
@@ -1976,7 +2213,12 @@ function biblio_admin_author_edit_form_submit($form, &$form_state) {
   }
 }
 
-
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_orphans_form($form_state) {
   $base = variable_get('biblio_base', 'biblio');
   $result = pager_query('SELECT distinct d.cid cid, name, affiliation
@@ -2000,6 +2242,13 @@ function biblio_admin_orphans_form($form_state) {
   );
   return $form;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_orphans_form_validate($form, &$form_state) {
   $check_count = array_filter($form_state['values']['authors']);
   if (count($check_count) == 0) {
@@ -2007,6 +2256,12 @@ function biblio_admin_orphans_form_validate($form, &$form_state) {
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_orphans_form_submit($form, &$form_state) {
   // Filter out unchecked authors
   $authors = array_filter($form_state['values']['authors']);
@@ -2014,6 +2269,13 @@ function biblio_admin_orphans_form_submit($form, &$form_state) {
   drupal_set_message(t('The orphaned authors ('.implode(',',$authors).') have been deleted.'));
 
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_orphans_form($form_state) {
   $base = variable_get('biblio_base', 'biblio');
   $result = pager_query('SELECT distinct bkd.kid kid, word
@@ -2037,6 +2299,13 @@ function biblio_admin_keyword_orphans_form($form_state) {
   );
   return $form;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_orphans_form_validate($form, &$form_state) {
   $check_count = array_filter($form_state['values']['keywords']);
   if (count($check_count) == 0) {
@@ -2044,6 +2313,12 @@ function biblio_admin_keyword_orphans_form_validate($form, &$form_state) {
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_orphans_form_submit($form, &$form_state) {
 
   $keywords = array_filter($form_state['values']['keywords']);
@@ -2053,6 +2328,12 @@ function biblio_admin_keyword_orphans_form_submit($form, &$form_state) {
 
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_edit_form($form_state, $keyword_id) {
   $base = variable_get('biblio_base', 'biblio');
 
@@ -2113,6 +2394,12 @@ function biblio_admin_keyword_edit_form($form_state, $keyword_id) {
   return $form;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_delete_confirm(&$form_state, $keyword_id) {
   $base = variable_get('biblio_base', 'biblio');
   $keyword = db_fetch_object(db_query('SELECT * FROM {biblio_keyword_data} bkd WHERE bkd.kid = %d ', $keyword_id));
@@ -2131,6 +2418,12 @@ function biblio_admin_keyword_delete_confirm(&$form_state, $keyword_id) {
 
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_delete_confirm_submit($form, &$form_state) {
   $base = variable_get('biblio_base', 'biblio');
   module_load_include('inc', 'biblio', 'includes/biblio.keywords');
@@ -2138,6 +2431,12 @@ function biblio_admin_keyword_delete_confirm_submit($form, &$form_state) {
   drupal_goto($base . '/keywords');
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_admin_keyword_edit_form_submit($form, &$form_state) {
   if ($form_state['values']['op'] == t('Save')) {
     drupal_write_record('biblio_keyword_data', $form_state['values'], 'kid');
diff --git a/includes/biblio.contributors.inc b/includes/biblio.contributors.inc
index e764696..3b7319d 100644
--- a/includes/biblio.contributors.inc
+++ b/includes/biblio.contributors.inc
@@ -1,119 +1,223 @@
 <?php
 /**
- * @param $aid
- * @return unknown_type
+ * @file
+ * Functions related to contributors in Drupal biblio module.
  */
-function biblio_get_contributor($aid) {
+
+/**
+ * Retrieves a biblio contributor object by contributor ID.
+ *
+ * // @todo: What happens if array or non-existant ID integer passed?
+
+ * @param integer $cid
+ *   Integer ID of a record in {biblio_contributor_data} table.
+ *
+ * @return object|?
+ *   A contributor object if found; otherwise ??
+ */
+function biblio_get_contributor($cid) {
   static $contributor = array();
-  if (!isset($contributor[$aid])) {
-    $contributor[$aid] = db_fetch_object(db_query('SELECT * FROM {biblio_contributor_data} WHERE cid = %d', $aid));
+  if (!isset($contributor[$cid])) {
+    $contributor[$cid] = db_fetch_object(db_query('SELECT * FROM {biblio_contributor_data} WHERE cid = %d', $cid));
   }
-
-  return $contributor[$aid];
+  return $contributor[$cid];
 }
 
+/**
+ * Retrieves biblio contributor object based on exact match of contributor name.
+ *
+ * // @todo: What happens if array or non-existant name string passed?
+ *
+ * @param string $name
+ *   Name of a contributor.
+ *
+ * @return object|?
+ *   A contributor object if found; otherwise ??
+ */
 function biblio_get_contributor_by_name($name) {
   return db_fetch_object(db_query("SELECT * FROM {biblio_contributor_data} bcd WHERE bcd.name = '%s'", array($name)));
 }
 
+/**
+ * Retrieves first biblio contributor object based on node revision ID.
+ *
+ * // @todo: What happens if array or non-existant ID passed?
+ *
+ * @param integer $vid
+ *   A node revision ID.
+ *
+ * @return object|?
+ *   A contributor object if found; otherwise ??
+ */
 function biblio_get_first_contributor($vid) {
   static $contributor = array();
   if (!isset($contributor[$vid])) {
-    $contributor[$vid] = db_fetch_object(db_query("SELECT * FROM {biblio_contributor} bc
-      INNER JOIN {biblio_contributor_data} bcd ON bc.cid=bcd.cid
-      WHERE bc.vid=%d AND bc.rank=0", $vid));
+    $sql = "SELECT * " .
+           "FROM {biblio_contributor} bc INNER JOIN {biblio_contributor_data} bcd ON bc.cid = bcd.cid " .
+           "WHERE bc.vid = %d AND bc.rank = 0";
+    $contributor[$vid] = db_fetch_object(db_query($sql, $vid));
   }
   return $contributor[$vid];
 }
 
 /**
- * @param $vid
- * @return unknown_type
+ * Retrieves all biblio contributor objects associated with node revision ID.
+ *
+ * // @todo: What happens if array or non-existant ID passed?
+ *
+ * @param integer $vid
+ *   A node revision ID.
+ *
+ * @return array
+ *   A array of contributor objects if $vid found; otherwise empty array.
  */
 function biblio_load_contributors($vid) {
   $contributors = array();
-  $query = "SELECT * FROM {biblio_contributor} bc
-      INNER JOIN {biblio_contributor_data} bcd ON bc.cid=bcd.cid
-      WHERE bc.vid=%d
-      ORDER BY bc.rank ASC"; // do not change order of presentation
-
-  $result = db_query($query, $vid);
-  while ($creator = db_fetch_array($result)) {
+  // Do not change order of presentation of contributors.
+  $sql = "SELECT * " .
+         "FROM {biblio_contributor} bc INNER JOIN {biblio_contributor_data} bcd ON bc.cid = bcd.cid " .
+         "WHERE bc.vid = %d " .
+         "ORDER BY bc.rank ASC";
+  $resource = db_query($sql, $vid);
+  while ($creator = db_fetch_array($resource)) {
     $contributors[$creator['auth_category']][] = $creator;
   }
   return $contributors;
 }
+
 /**
- * Add separate author named "et al" to the end of the author array
+ * Adds additional author named "et al" to the end of the author array.
+ *
+ * @param $authors -
+ *   Array of author arrays to possibly augment.
+ * @param integer $type
+ *   Integer ID representing the author type.
  *
- * @param $authors - author array to augment
- * @param $type - auth_type
- * @return true if author was added, false if "etal" was already there
+ * @return bool
+ *   TRUE if author was added, FALSE if "et al" already present.
  */
-function biblio_authors_add_etal (&$authors, $type) {
-  $etal = "et al"; $max_rank = 0;
+function biblio_authors_add_etal(&$authors, $type) {
+  $etal = "et al";
+  $max_rank = 0;
   foreach ($authors as $author) { // et al author should be added only once per type
     if ($author['auth_type'] != $type) continue;
-    if ($author['name'] == $etal) return false;
+    if ($author['name'] == $etal) {
+      return FALSE;
+    }
     $max_rank = max($max_rank, $author['rank']);
   }
   $authors[] = biblio_parse_author(array('name' => $etal, 'auth_type' => $type, 'lastname' => $etal, 'rank' => $max_rank + 1));
   return true;
 }
+
 /**
- * Parse initial contributor array and augment with additional info
- * @param $contributors initial contributor array
- * @return augmented contributor array
+ * Parses array of contributors and augments with additional information.
+ *
+ * @param array $contributors
+ *   Array of contibutor arrays
+ *
+ * @return array|null
+ *   An array of enhanced author arrays.
  */
 function biblio_parse_contributors($contributors) {
   $result = array();
-  if (!count($contributors)) return;
-  foreach ($contributors as $cat => $authors) {
+  if (count($contributors) < 1) {
+    // @todo: Should something be returned here?
+    return;
+  }
+  foreach ($contributors as $category => $authors) {
     $etal = array();
     foreach ($authors as $author) {
-      // remove any form of "et al" from name field, because it confuses biblio_parse_author
+      // Remove any form of "et al" from name element for biblio_parse_author().
       $author_cleaned = preg_replace("/et\.?\s+al\.?/", '', $author['name']);
-      if ($author_cleaned != $author['name']) { // if "et al" was present:
-        $author['name'] = $author_cleaned;  // store cleaned name
-        $etal[$author['auth_type']] = TRUE; // mark it as "to be added" in $etal array
-    }
+      // If "et al" was present, store cleaned version for parsing.
+      if ($author_cleaned != $author['name']) {
+        $author['name'] = $author_cleaned;
+        // Mark this author as "to be added" in $etal array
+        $etal[$author['auth_type']] = TRUE;
+      }
       $author['name'] = trim($author['name']);
       if (strlen($author['name'])) {
-        $result[$cat][] = biblio_parse_author($author, $cat);
+        $result[$category][] = biblio_parse_author($author, $category);
       }
     }
-    // add "et al" authors for all neccessary author types
+    // Add "et al" authors for all neccessary contrbutor categories
     foreach ($etal as $type => $dummy) {
-      if (isset($result[$cat])) { // add "et al" only if plain authors exists
-        biblio_authors_add_etal($result[$cat], $type);
+      // Add "et al" only if plain authors exists.
+      if (isset($result[$category])) {
+        biblio_authors_add_etal($result[$category], $type);
       }
     }
   }
   return $result;
 }
 
+/**
+ * Deletes all contributors associated with node ID.
+ *
+ * // @todo: Refactor to take a node ID or a node object?
+ * // @todo: Shouldn't this return success?
+ *
+ * @param object $node
+ *   A node object that contains a property 'nid'.
+ *
+ * @return null
+ *   ? change to $success?
+ */
 function biblio_delete_contributors($node) {
   db_query('DELETE FROM {biblio_contributor} WHERE nid = %d', array(':nid' => $node->nid));
   return;
 }
 
+/**
+ * Deletes all contributors revisions associated with node revision ID.
+ *
+ * // @todo: Refactor to take a node revision ID or a node object?
+ *
+ * @param object $node
+ *   A node object that contains a property 'vid'.
+ *
+ * @return integer
+ *   Number of revisions deleted for supplied
+ */
 function biblio_delete_contributors_revision($node) {
   db_query('DELETE FROM {biblio_contributor} WHERE vid = %d', array(':vid' => $node->vid));
   $count = db_affected_rows();
   return $count;
 }
 
+/**
+ * Deletes a contributor based upon contributor ID.
+ *
+ * @param int $cid
+ *   The ID of a contributor.
+ *
+ * @return integer
+ *   The number of contributor records deleted for contributor ID.
+ */
 function biblio_delete_contributor($cid) {
+  $count = 0;
+
+  // @todo: Don't we want to delete x=ref data records first in case of failure
+  //        in mid-process?
   db_query('DELETE FROM {biblio_contributor}
             WHERE cid = %d', array(':cid' => $cid));
 
   db_query('DELETE FROM {biblio_contributor_data}
             WHERE cid = %d', array(':cid' => $cid));
-
   $count = db_affected_rows();
   return $count;
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_delete_contributor_revision($cid, $vid) {
   db_query('DELETE FROM {biblio_contributor}
             WHERE cid = %d and vid = %d', array(':cid' => $cid, ':vid' => $vid));
@@ -122,11 +226,29 @@ function biblio_delete_contributor_revision($cid, $vid) {
   return $count;
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_count_orphan_authors() {
 
   return db_result(db_query('SELECT COUNT(*) FROM {biblio_contributor_data} bcd WHERE bcd.cid NOT IN (SELECT DISTINCT(bc.cid) FROM {biblio_contributor} bc )'));
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_get_orphan_authors() {
   $authors = array();
   $result = db_query('SELECT distinct d.cid cid, name, affiliation
@@ -140,6 +262,15 @@ function biblio_get_orphan_authors() {
   return $authors;
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_delete_orphan_authors($force = FALSE) {
   if (variable_get('biblio_auto_orphaned_author_delete', 0) || $force) {
     $active_cids = array();
@@ -158,7 +289,7 @@ function biblio_delete_orphan_authors($force = FALSE) {
     $orphans = array_diff($all_cids, $active_cids);
 
     if (!empty($orphans)) {
-      db_query('DELETE FROM {biblio_contributor_data} WHERE cid IN ('. implode(',', $orphans) .')');
+      db_query('DELETE FROM {biblio_contributor_data} WHERE cid IN (' . implode(',', $orphans) . ')');
       $count = db_affected_rows();
       $message = t('%count orphaned authors were deleted from the biblio_contributor_data table.', array('%count' => $count));
       watchdog('biblio_cron', $message);
@@ -166,25 +297,70 @@ function biblio_delete_orphan_authors($force = FALSE) {
   }
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_insert_contributors($node) {
   if (empty ($node->biblio_contributors)) return true;
-  return _save_contributors($node->biblio_contributors, $node->nid, $node->vid);
+  return _biblio_save_contributors($node->biblio_contributors, $node->nid, $node->vid);
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_update_contributors($node) {
-  _save_contributors($node->biblio_contributors, $node->nid, $node->vid, TRUE);
+  _biblio_save_contributors($node->biblio_contributors, $node->nid, $node->vid, TRUE);
   return;
-
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_save_contributor(&$author) {
   return drupal_write_record('biblio_contributor_data', $author);
 }
 
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function biblio_update_contributor(&$author) {
   if (!isset($author['cid'])) return false;
   return drupal_write_record('biblio_contributor_data', $author, 'cid');
 }
+
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function _biblio_contributor_sort(&$authors) {
   foreach($authors as $key => $author) {
     if(!isset($author['rank'])) {
@@ -193,40 +369,65 @@ function _biblio_contributor_sort(&$authors) {
   }
   usort($authors, '_biblio_contributor_usort');
 }
+
+/**
+ *
+ *
+ * @param
+ *
+ *
+ * @return
+ *
+ */
 function _biblio_contributor_usort($a, $b) {
   if(empty($a['name'])) return 1;
   if(empty($b['name'])) return -1;
   return ($a['rank'] < $b['rank']) ? -1 : 1;
 }
+
 /**
- * Save contributors to the database
- * @param $authors
+ * Save contributors to the database.
+ *
+ *
+ *
+ *
+ * @param $contributors
+ *
  * @param $nid
+ *
  * @param $vid
+ *
  * @param $update
+ *   (optional) A logical flag indicating whether ...
+ *
  * @return success of database operations
+ *
  */
-function _save_contributors(&$contributors, $nid, $vid, $update = FALSE) {
+function _biblio_save_contributors(&$contributors, $nid, $vid, $update = FALSE) {
   $rank = 0;
   db_query('DELETE FROM {biblio_contributor} WHERE nid = %d AND vid = %d', array($nid, $vid));
   if (is_array($contributors) && count($contributors)) {
     foreach ($contributors as $cat => $authors) {
-      _biblio_contributor_sort($authors); // re-sort the authors by rank because the rank may have changed due to tabledrag on the input form
+      // Re-sort the authors by rank because the rank may have changed due to
+      // javascript tabledrag on the input form.
+      _biblio_contributor_sort($authors);
       foreach ($authors as $key => $author) {
         if (!empty($author['name'])) {
           if(empty($author['lastname'])) {
             $md5_in = isset($author['md5']) ? $author['md5'] : '';
             $contributors[$cat][$key] = $author = biblio_parse_author($author, $cat);
             if ($md5_in != $author['md5'] && !empty($author['cid'])) {
-              $author['cid'] = null;
+              $author['cid'] = NULL;
             }
           }
           if (empty ($author['cid']) && isset($author['md5'])) {
-            $author['cid'] = _get_cid_from_md5($author['md5']);
+            $author['cid'] = _biblio_get_cid_from_md5($author['md5']);
           }
           if (empty ($author['cid'])) {
             biblio_save_contributor($author);
-            if (empty ($author['cid'])) return false;
+            if (empty($author['cid'])) {
+              return FALSE;
+            }
           }
 
           $link_array = array(
@@ -238,55 +439,72 @@ function _save_contributors(&$contributors, $nid, $vid, $update = FALSE) {
             'auth_category' => $cat,
           );
 
-          if (!drupal_write_record('biblio_contributor', $link_array)) return false;
+          if (!drupal_write_record('biblio_contributor', $link_array)) {
+            return FALSE;
+          }
         }
       }
     }
   }
   db_query("UPDATE {biblio_contributor_data} SET aka = cid WHERE aka = 0 OR aka IS NULL");
-  return true; // successfully saved all contributors
+  return TRUE;
 }
-/*
- Released through http://bibliophile.sourceforge.net under the GPL licence.
- Do whatever you like with this -- some credit to the author(s) would be appreciated.
 
- A collection of PHP classes to manipulate bibtex files.
-
- If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net so that your improvements can be added to the release package.
-
- Mark Grimshaw 2004/2005
- http://bibliophile.sourceforge.net
-
- 28/04/2005 - Mark Grimshaw.
- Efficiency improvements.
-
- 11/02/2006 - Daniel Reidsma.
- Changes to preg_matching to account for Latex characters in names such as {\"{o}}
- */
-// For a quick command-line test (php -f PARSECREATORS.php) after installation, uncomment these lines:
-/***********************
- $authors = "Mark \~N. Grimshaw and Bush III, G.W. & M. C. H{\\'a}mmer Jr. and von Frankenstein, Ferdinand Cecil, P.H. & Charles Louis Xavier Joseph de la Vallee P{\\\"{o}}ussin";
- $creator = new PARSECREATORS();
- $creatorArray = $creator->parse($authors);
- print_r($creatorArray);
- ***********************/
-/* Create writer arrays from bibtex input.
- 'author field can be (delimiters between authors are 'and' or '&'):
- 1. <first-tokens> <von-tokens> <last-tokens>
- 2. <von-tokens> <last-tokens>, <first-tokens>
- 3. <von-tokens> <last-tokens>, <jr-tokens>, <first-tokens>
- */
 /**
- * @param $author_array
- * @return unknown_type
+ * Parses an author name into its component parts.
+ *
+ * This function is partly based on a collection of PHP classes to manipulate
+ * bibtex files and other work at http://bibliophile.sourceforge.net.
+ *
+ * That work was released through http://bibliophile.sourceforge.net under the
+ * GPL licence. Do whatever you like with this -- some credit to the author(s)
+ * would be appreciated. If you make improvements, please consider contacting
+ * the administrators at bibliophile.sourceforge.net so that your improvements
+ * can be added to the release package.
+ *
+ * Mark Grimshaw 2004/2005
+ * http://bibliophile.sourceforge.net
+ *
+ * 28/04/2005 - Mark Grimshaw.
+ * Efficiency improvements.
+ *
+ * 11/02/2006 - Daniel Reidsma.
+ * Changes to preg_matching to account for Latex characters in names such as
+ * {\"{o}}.
+ *
+ * @param string|array $contributor
+ *   A string representing a name or an array with
+ * @param $category_id
+ *   (optional)
+ *
+ * @return array|false
+ *   FALSE if there was an error; otherwise, an associative array for the parsed
+ *   parts of a name, including at minimum the keys:
+ *   - name:
+ *   - firstname:
+ *   - initials:
+ *   - lastname:
+ *   - prefix:
+ *   - md5:
  */
-function biblio_parse_author($author_array, $cat = 0) {
+function biblio_parse_author($contributor, $category_id = 0) {
+  if (is_string($contributor)) {
+    $author_array = array();
+    $author_array['name'] = $contributor;
+  }
+  elseif (is_array($contributor) && isset($contributor['name'])) {
+    $author_array = $contributor;
+  }
+  else {
+    return FALSE;
+  }
 
-  if ($cat == 5){
+  if ($category_id == 5) {
     $author_array['firstname'] = '';
     $author_array['initials'] = '';
     $author_array['lastname'] = trim($author_array['name']);
     $author_array['prefix'] = '';
+    // @todo: set suffix to empty string?
   }
   else {
     $value = trim($author_array['name']);
@@ -295,76 +513,119 @@ function biblio_parse_author($author_array, $cat = 0) {
     $value = preg_replace("/\s{2,}/", ' ', $value); // replace multiple white space by single space
     $author = explode(",", $value);
     $size = sizeof($author);
-    // No commas therefore something like Mark Grimshaw, Mark Nicholas Grimshaw, M N Grimshaw, Mark N. Grimshaw
+    // If only one element to author array, no commas were found.  Therefore,
+    // the name is something like Mark Grimshaw | Mark Nicholas Grimshaw |
+    // Mark N. Grimshaw | M N Grimshaw | or such.
     if ($size == 1) {
       // Is complete surname enclosed in {...}, unless the string starts with a backslash (\) because then it is
       // probably a special latex-sign..
       // 2006.02.11 DR: in the last case, any NESTED curly braces should also be taken into account! so second
       // clause rules out things such as author="a{\"{o}}"
       //
-      if (preg_match("/(.*){([^\\\].*)}/", $value, $matches) && !(preg_match("/(.*){\\\.{.*}.*}/", $value, $matches2))) {
+      if (preg_match("/(.*){([^\\\].*)}/", $value, $matches) &&
+        !(preg_match("/(.*){\\\.{.*}.*}/", $value, $dummy))) {
         $author = explode(" ", $matches[1]);
         $surname = $matches[2];
       }
       else {
         $author = explode(" ", $value);
-        // last of array is surname (no prefix if entered correctly)
+        // Last of element of array is surname (no prefix if entered correctly).
         $surname = array_pop($author);
       }
     }
-    // Something like Grimshaw, Mark or Grimshaw, Mark Nicholas  or Grimshaw, M N or Grimshaw, Mark N.
-    else
-    if ($size == 2) {
-      // first of array is surname (perhaps with prefix)
-      list ($surname, $prefix) = _grabSurname(array_shift($author));
+
+    // If one comma present, name has a pattern something like Grimshaw, Mark |
+    // Grimshaw, Mark Nicholas | Grimshaw, M N | Grimshaw, Mark N.
+    elseif ($size == 2) {
+      // First element of array is surname (perhaps with a prefix).
+      list($surname, $prefix) = _biblio_extract_surname_parts(array_shift($author));
     }
-    // If $size is 3, we're looking at something like Bush, Jr. III, George W
+
+    // If $size is 3, name is something like Bush, Jr. III, George W
     else {
-      // middle of array is 'Jr.', 'IV' etc.
+      // Middle element of array is 'Jr.', 'IV', etc.
       $appellation = implode(' ', array_splice($author, 1, 1));
-      // first of array is surname (perhaps with prefix)
-      list ($surname, $prefix) = _grabSurname(array_shift($author));
+      // First element of array is surname (perhaps with prefix).
+      list($surname, $prefix) = _biblio_extract_surname_parts(array_shift($author));
     }
     $remainder = implode(" ", $author);
-    list ($firstname, $initials, $prefix2) = _grabFirstnameInitials($remainder);
-    if (!empty ($prefix2))
-    $prefix .= $prefix2;
-    //var_dump($prefix);
-    //$surname = $surname . ' ' . $appellation;
+    list($firstname, $initials, $prefix2) = _biblio_extract_firstname_initials($remainder);
+    if (!empty($prefix2)) {
+      $prefix .= $prefix2;
+    }
     $author_array['firstname'] = trim($firstname);
     $author_array['initials'] = trim($initials);
     $author_array['lastname'] = trim($surname);
     $author_array['prefix'] = trim($prefix);
     $author_array['suffix'] = trim($appellation);
   }
-  $author_array['md5'] =  _md5sum($author_array);
+  $author_array['md5'] = biblio_calculate_contributor_hash($author_array);
   return $author_array;
 }
+
 /**
- * @param $creator
- * @return unknown_type
+ * Creates an md5 hash string to ease contributor comparison logic.
+ *
+ * @param string|array $contributor
+ *   A string with a name or array with one or more of the following elements,
+ *   at least one of which is not empty:
+ *   - firstname:
+ *   - intiials:
+ *   - prefix:
+ *   - lastname:
+ *
+ * @return string
+ *   An md5 hash string.
  */
-function _md5sum($creator) {
-  $string = $creator['firstname'] . $creator['initials'] . $creator['prefix'] .$creator['lastname'];
+function biblio_calculate_contributor_hash($contributor) {
+  $hash = '';
+  if (is_string($contributor)) {
+    $creator = biblio_parse_author(array('name' => trim($contributor)));
+  }
+  elseif (is_array($contributor)) {
+    $creator = $contributor;
+  }
+  else {
+    return $hash;
+  }
+
+  $firstname = isset($creator['firstname']) ? $creator['firstname'] : '';
+  $initials = isset($creator['initials']) ? $creator['initials'] : '';
+  $prefix = isset($creator['prefix']) ? $creator['prefix'] : '';
+  $lastname = isset($creator['lastname']) ? $creator['lastname'] : '';
+
+  $string = $firstname . $initials . $prefix . $lastname;
   $string = str_replace(' ', '', drupal_strtolower($string));
-  return md5($string);
+  if (!empty($string)) {
+    $hash = md5($string);
+  }
+  return $hash;
 }
-// grab firstname and initials which may be of form "A.B.C." or "A. B. C. " or " A B C " etc.
+
 /**
+ *
+ *
+ * grab firstname and initials which may be of form "A.B.C." or "A. B. C. " or " A B C " etc.
+ *
  * @param $remainder
- * @return unknown_type
+ *   The string representing the remainder of a name.
+ *
+ * @return array
+ *   An array of three values: firstname, initials, prefix.
  */
-function _grabFirstnameInitials($remainder) {
+function _biblio_extract_firstname_initials($remainder) {
   $prefix = array();
   $firstname = $initials = '';
   $array = explode(" ", $remainder);
   foreach ($array as $value) {
     $firstChar = drupal_substr($value, 0, 1);
-    if ((ord($firstChar) >= 97) && (ord($firstChar) <= 122)){
-    $prefix[] = $value;
-    } else if (preg_match("/[a-zA-Z]{2,}/", trim($value))){
+    if ((ord($firstChar) >= 97) && (ord($firstChar) <= 122)) {
+      $prefix[] = $value;
+    }
+    elseif (preg_match("/[a-zA-Z]{2,}/", trim($value))) {
       $firstnameArray[] = trim($value);
-    } else {
+    }
+    else {
       $initialsArray[] = trim(str_replace(".", " ", trim($value)));
     }
   }
@@ -377,18 +638,26 @@ function _grabFirstnameInitials($remainder) {
   if (!empty ($prefix)){
     $prefix = implode(" ", $prefix);
   }
-  return array($firstname,$initials,$prefix);
+  return array($firstname, $initials, $prefix);
 }
-// surname may have title such as 'den', 'von', 'de la' etc. - characterised by first character lowercased.  Any
-// uppercased part means lowercased parts following are part of the surname (e.g. Van den Bussche)
+
 /**
+ * Splits a surname string into its prefix and surname parts.
+ *
+ * A surname may have a title portion, such as 'den', 'von', 'de la', which are
+ * characterised by a lowercased first character. Any uppercased part means
+ * lowercased parts following are part of the surname (e.g. Van den Bussche).
+ *
  * @param $input
- * @return unknown_type
+ *   A string representing a name with a possible prefix.
+ *
+ * @return array
+ *   An array with two elements representing surname and name prefix.
  */
-function _grabSurname($input) {
+function _biblio_extract_surname_parts($input) {
   $noPrefix = FALSE;
   $surname = FALSE;
-  $prefix  = FALSE;
+  $prefix = FALSE;
 
   $surnameArray = explode(" ", $input);
 
@@ -410,17 +679,23 @@ function _grabSurname($input) {
   }
   return array($surname, $prefix);
 }
+
 /**
- * @return unknown_type
+ * Returns array of md5 hash strings for all biblio contributors.
+ *
+ * // @todo: Is this function presently used anywhere?
+ *
+ * @return array|null
+ *   An array of md5 hash values; otherwise null if no contributors.
  */
-function _loadMD5() {
+function _biblio_load_contributor_hashes() {
   static $md5   = array();
   static $count = 0;
   $db_count = db_result(db_query("SELECT COUNT(*) FROM {biblio_contributor_data}"));
   if ($db_count != $count){
     $count = $db_count;
     $md5 = array();
-    $result = db_query('SELECT md5,cid  FROM {biblio_contributor_data} ');
+    $result = db_query('SELECT md5,cid FROM {biblio_contributor_data}');
     while ($row = db_fetch_array($result)) {
       $md5[$row['cid']] = $row['md5'];
     }
@@ -428,17 +703,43 @@ function _loadMD5() {
   return (count($md5)) ? $md5 : NULL;
 }
 
-function _get_cid_from_md5($md5) {
+/**
+ * Retrieves a contributor ID value based on md5 hash value.
+ *
+ * // @todo: What is returned if no match found for md5 hash string?
+ *
+ * @param string $md5
+ *   A md5 hash string.
+ *
+ * @return integer
+ *   Integer ID of a contributor.
+ */
+function _biblio_get_cid_from_md5($md5) {
   return db_result(db_query("SELECT cid FROM {biblio_contributor_data} WHERE md5='%s'", $md5));
 }
 
+/**
+ *
+ *
+ * This function does what...
+ *
+ * @param object $user
+ *   A user object with uid property.
+ * @param object $node
+ *   A node object.
+ *
+ * @return true|null
+ *   TRUE if the user ID matches the author Drupal user ID; otherwsie NULL.
+ */
 function biblio_contributor_user_access($user, $node) {
   if(isset($node->biblio_contributors) && is_array($node->biblio_contributors)) {
     foreach ($node->biblio_contributors as $cat => $authors) {
       foreach ($authors as $key => $author) {
-        if ($author['drupal_uid'] == $user->uid) return TRUE;
+        if ($author['drupal_uid'] == $user->uid) {
+          return TRUE;
+        }
       }
     }
   }
   return;
-}
\ No newline at end of file
+}
diff --git a/includes/biblio.import.export.inc b/includes/biblio.import.export.inc
index 1e0bd1b..2e64062 100644
--- a/includes/biblio.import.export.inc
+++ b/includes/biblio.import.export.inc
@@ -1,35 +1,19 @@
-<?PHP
-
+<?php
 /**
  * @file
  * Functions that are used to import and export biblio data.
  *
- */
-/*   biblio.import.export.inc
- *
- *   Copyright (C) 2006-2008  Ron Jerome
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License along
- *   with this program; if not, write to the Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Copyright (C) 2006-2012  Ron Jerome
  *
  */
+
 /**
  * Return a form select box populated with all the users of the site.
  *
  * @param $my_uid
  *   The user id of the person accessing the form so the select box defaults
  *   to their userid
+ *
  * @return
  *   An array which will be used by the form builder to add a select box to a form
  */
@@ -49,13 +33,12 @@ function _biblio_admin_build_user_select($my_uid) {
   );
   return $select;
 }
+
 /**
- * Return a form used to import files into biblio.
+ * Defines a form used to import files into biblio.
  *
- * @return
- *   An array which will be used by the form builder to build the import form
  */
-function biblio_import_form() {
+function biblio_import_form(&$form_state) {
   global $user;
   if (biblio_access('import')) { // && !user_access('administer nodes')) {
     $form['#attributes']['enctype'] = 'multipart/form-data';
@@ -103,14 +86,15 @@ function biblio_import_form() {
         $freetag_vocab = $vocabularies[variable_get('biblio_keyword_vocabulary', 0)];
         unset($vocabularies[variable_get('biblio_keyword_vocabulary', 0)]);
         $msg = t('<b>NOTE:</b> Keyword "free tagging" is turned on, consequently all incomming keywords will be added to the <b>@name</b> vocabulary as specified in the "Keyword" section of the !url page.', array ('@name' => $freetag_vocab->name, '!url' => l(t('admin/settings/biblio'), 'admin/settings/biblio')));
-      } else {
+      }
+      else {
         $msg = t('<b>NOTE:</b> Keyword "free tagging" is turned off, consequently keywords will <b>NOT</b> be added to the vocabulary as specified in the Taxonomy section of the !url page.', array ('!url' => l(t('admin/settings/biblio'), 'admin/settings/biblio')));
       }
       $i = 0;
       foreach ($vocabularies as $vocabulary) {
-        $form['import_taxonomy']['vocabulary'. $i] = module_invoke('taxonomy', 'form', $vocabulary->vid, 0);
-        $form['import_taxonomy']['vocabulary'. $i]['#weight'] = $vocabulary->weight;
-        $form['import_taxonomy']['vocabulary'. $i++]['#description'] = t("Select taxonomy term to be assigned to imported entries");
+        $form['import_taxonomy']['vocabulary' . $i] = module_invoke('taxonomy', 'form', $vocabulary->vid, 0);
+        $form['import_taxonomy']['vocabulary' . $i]['#weight'] = $vocabulary->weight;
+        $form['import_taxonomy']['vocabulary' . $i++]['#description'] = t("Select taxonomy term to be assigned to imported entries");
       }
       $form['import_taxonomy']['copy_to_biblio'] = array(
         '#type' => 'checkbox',
@@ -120,12 +104,13 @@ function biblio_import_form() {
         '#description' => t('If this option is selected, the selected taxonomy terms will be copied to the @biblio_title keyword database and be displayed as keywords (as well as taxonomy terms) for this entry.', array('@biblio_title' => variable_get('biblio_base_title', 'Biblio')))
       );
 
-    } else {
+    }
+    else {
       if (module_exists('taxonomy')){
         $vocab_msg = t('There are currently no vocabularies assigned to the biblio node type, please go the the !url page to fix this', array ('!url' => l(t('admin/content/taxonomy'), 'admin/content/taxonomy')));
-      }else{
+      }
+      else{
         $vocab_msg = '<div class="admin-dependencies">'. t('Depends on') .': '. t('Taxonomy') .' (<span class="admin-disabled">'. t('disabled') .'</span>)</div>';
-
       }
       $form['import_taxonomy']['vocabulary_message'] = array (
         '#value' => '<p><div>'. $vocab_msg .'</div></p>'
@@ -136,14 +121,15 @@ function biblio_import_form() {
     );
     $form['button'] = array ('#type' => 'submit', '#value' => t('Import'));
     return $form;
-  } else {
+  }
+  else {
     drupal_set_message("You are not authorized to access the biblio import page", 'error');
     print theme('page', '');
   }
 }
 
 /**
- * Implementation of hook_validate() for the biblio_import_form.
+ * Implements hook_validate() for the biblio_import_form.
  */
 function biblio_import_form_validate($form, & $form_state) {
   $op = $form_state['values']['op'];
@@ -152,16 +138,22 @@ function biblio_import_form_validate($form, & $form_state) {
     switch ($error){
       case 1: form_set_error('biblio_import_form', t("The uploaded file exceeds the upload_max_filesize directive in php.ini."));
       break;
+
       case 2: form_set_error('biblio_import_form', t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form."));
       break;
+
       case 3: form_set_error('biblio_import_form', t("The uploaded file was only partially uploaded."));
       break;
+
       case 4: form_set_error('biblio_import_form', t("No file was uploaded."));
       break;
+
       case 6: form_set_error('biblio_import_form', t("Missing a temporary folder."));
       break;
+
       case 7: form_set_error('biblio_import_form', t("Failed to write file to disk."));
       break;
+
       case 8: form_set_error('biblio_import_form', t("File upload stopped by extension."));
     }
   }
@@ -171,6 +163,15 @@ function biblio_import_form_validate($form, & $form_state) {
   }
 }
 
+/**
+ *
+ *
+ * @param $source
+ *
+ *
+ * @return array
+ *
+ */
 function biblio_file_save_uploads($source) {
   $files = array();
   if (isset($_FILES[$source]) && is_array($_FILES[$source] )) {
@@ -187,6 +188,12 @@ function biblio_file_save_uploads($source) {
   return $files;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_import_form_submit($form, & $form_state) {
   global $user;
   if ($form_state['values']['op'] == t('Import') && isset ($form_state['values']['filetype'])) {
@@ -259,6 +266,12 @@ function biblio_import_form_submit($form, & $form_state) {
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_import_batch_operations($session_id, $user, $userid, $terms, &$context) {
   $limit = 10;
   if (empty($context['sandbox'])) {
@@ -313,6 +326,12 @@ function biblio_import_batch_operations($session_id, $user, $userid, $terms, &$c
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_import_batch_finished($success, $results, $operations) {
 
   biblio_import_finalize($success, $results);
@@ -321,6 +340,12 @@ function biblio_import_batch_finished($success, $results, $operations) {
 
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_import_finalize($success, $results) {
   $format = $results['format'];
   $nids = $results['nids'];
@@ -368,6 +393,12 @@ function biblio_import_finalize($success, $results) {
 
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_import_from_url($URL) {
   $handle = fopen($URL, "r"); // fetch data from URL in read mode
   $data = "";
@@ -388,6 +419,12 @@ function biblio_import_from_url($URL) {
   return $data;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_export_form() {
   $form['pot'] = array (
     '#type' => 'fieldset',
@@ -403,6 +440,13 @@ function biblio_export_form() {
 
   return $form;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_export_form_submit($form, & $form_state) {
   if ($form_state['values']['op'] == t('Export translation data')) {
     biblio_dump_db_data_for_pot();
@@ -411,7 +455,7 @@ function biblio_export_form_submit($form, & $form_state) {
 }
 
 /**
- * Import data from a file and return the node ids created.
+ * Imports data from a file and return the node ids created.
  *
  * @param $userid
  *   The user id of that will be assigned to each node imported
@@ -421,6 +465,7 @@ function biblio_export_form_submit($form, & $form_state) {
  *   The format of the file to be imported (tagged, XML, RIS, bibTEX)
  * @param $terms
  *   the vocabulary that the imported nodes will be associated with
+ *
  * @return
  *   An array the node id's of the items imported
  */
@@ -454,20 +499,22 @@ function biblio_import($import_file, $type, $userid = 1, $terms = NULL, $batch =
 
   return ;
 }
+
 /**
- * Export nodes in a given file format.
+ * Exports biblio nodes in a given file format.
  *
  * @param $format
  *   The file format to export the nodes in (tagged, XML, bibTEX)
  * @param $nid
- *   If not NULL, then export only the given nodeid, else we will
+ *   If not NULL, then export only the given node ID, else we will
  *   use the session variable which holds the most recent query. If neither
  *   $nid or the session variable are set, then nothing is exported
  * @param $version
  *   The version of EndNote XML to use.  There is one format for ver. 1-7 and
  *   a different format for versions 8 and greater.
+ *
  * @return
- *   none
+ *   ??
  */
 function biblio_export($format = "tagged", $nid = null, $popup = false, $version = 8) {
   $params = array ();
@@ -478,7 +525,8 @@ function biblio_export($format = "tagged", $nid = null, $popup = false, $version
   elseif (!empty ($nid)) {
     $query = db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n  WHERE n.nid=%d ");
     $params[] = $nid;
-  } else {
+  } 
+  else {
     return;
   }
   $result = db_query($query, $params);
@@ -496,15 +544,17 @@ function biblio_export($format = "tagged", $nid = null, $popup = false, $version
     }
   }
 
-  if ($popup && !empty($popup_data)) return '<pre>' . $popup_data . '</pre>';
-
+  if ($popup && !empty($popup_data)) { 
+    return '<pre>' . $popup_data . '</pre>';
+  }
 }
 
 /**
- * Save node imported from a file.
+ * Saves a biblio node imported from a file.
  *
  * @param $node_array
  *   a 2 dimensional array containing all the node information
+ *
  * @return
  *   The node ids of the saved nodes
  */
@@ -522,6 +572,13 @@ function biblio_save_imported_nodes(& $node_array) {
 */
   return $node_ids;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_save_node($node, $batch = FALSE, $session_id = NULL, $save_node = TRUE) {
   global $user;
 
@@ -559,9 +616,12 @@ function biblio_save_node($node, $batch = FALSE, $session_id = NULL, $save_node
   }
 }
 
-
-
-
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_csv_export_2($result, $bfields) {
   //  $query_biblio_fields = 'SELECT name, title FROM {biblio_fields}';
   //  $res_biblio_fields = db_query($query_biblio_fields);
@@ -630,6 +690,13 @@ function biblio_csv_export_2($result, $bfields) {
   drupal_set_header('Content-Disposition: attachment; filename=biblio_export.csv');
   return $csv;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 //function _biblio_cck_join($biblio_fields = array()) {    // works not with php4
 function _biblio_cck_join(& $biblio_fields) {
   $cck_join = '';
@@ -645,6 +712,12 @@ function _biblio_cck_join(& $biblio_fields) {
   return $cck_join;
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_backup() {
 
   $csv_function = (!function_exists('fputcsv')) ? 'biblio_fputcsv' : 'fputcsv';
@@ -699,10 +772,22 @@ function biblio_backup() {
   }
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_restore(& $csv_content, $mode = 'create') {
 
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_csv_export($results) {
   $csv = '';
   if (!is_array($results)) {
@@ -721,6 +806,12 @@ function biblio_csv_export($results) {
   return($csv);
 }
 
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_strcsv($fields = array(), $delimiter = ',', $enclosure = '"') {
   $str = '';
   $escape_char = '\\';
@@ -750,6 +841,13 @@ function biblio_strcsv($fields = array(), $delimiter = ',', $enclosure = '"') {
   $str .= "\n";
   return $str;
 }
+
+/**
+ *
+ *
+ *
+ *
+ */
 function biblio_dump_db_data_for_pot() {
   $query = "SELECT name, description FROM {biblio_types} ";
   $result = db_query($query);
@@ -779,4 +877,3 @@ function biblio_dump_db_data_for_pot() {
   drupal_set_header('Content-Disposition: attachment; filename=biblio_db_values.pot');
   print $output;
 }
-
diff --git a/includes/biblio.keywords.inc b/includes/biblio.keywords.inc
index 1f17346..f86bf69 100644
--- a/includes/biblio.keywords.inc
+++ b/includes/biblio.keywords.inc
@@ -1,28 +1,19 @@
 <?php
 /**
- *   biblio.module for Drupal
- *
- *   Copyright (C) 2006-2009  Ron Jerome
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License along
- *   with this program; if not, write to the Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * @file
+ * Keywords related functions for Drupal biblio module.
  *
+ * Copyright (C) 2006-2012  Ron Jerome
  */
 
 /**
- * @param $name
- * @return array of keywords
+ * Retrieves a keyword object by keyword name.
+ *
+ * @param string $name
+ *   String of the name to use for an exact lowercase match.
+ *
+ * @return object|false
+ *   The keyword object if name was found; otherwise FALSE.
  */
 function biblio_get_keyword_by_name($name) {
   static $keywords = array();
@@ -37,28 +28,34 @@ function biblio_get_keyword_by_name($name) {
       return FALSE;
     }
   }
-
   return $keywords[$kid];
 }
 
 /**
- * @param $kid
- * @return unknown_type
+ * Retrieves a keyword object by keyword ID.
+ *
+ * @param integer $keyword_id
+ *
+ *
+ * @return object
+ *
  */
-function biblio_get_keyword_by_id($kid) {
+function biblio_get_keyword_by_id($keyword_id) {
   static $keywords = array();
-
-  if (!isset($keywords[$kid])) {
-    $keywords[$kid] = db_fetch_object(db_query('SELECT * FROM {biblio_keyword_data} WHERE kid = %d', $kid));
+  if (!isset($keywords[$keyword_id])) {
+    $keywords[$keyword_id] = db_fetch_object(db_query('SELECT * FROM {biblio_keyword_data} WHERE kid = %d', $keyword_id));
   }
-
-  return $keywords[$kid];
-
+  return $keywords[$keyword_id];
 }
 
 /**
- * @param unknown_type $node
- * @return unknown_type
+ *
+ *
+ * @param object $node
+ *
+ *
+ * @return integer
+ *
  */
 function biblio_delete_keywords($node) {
   db_query('DELETE FROM {biblio_keyword} WHERE nid = %d', $node->nid);
@@ -66,10 +63,28 @@ function biblio_delete_keywords($node) {
   return $count;
 }
 
+/**
+ *
+ *
+ * @param object $node
+ *
+ *
+ * @return
+ *
+ */
 function biblio_update_keywords($node) {
   biblio_insert_keywords($node, TRUE);
 }
 
+/**
+ *
+ *
+ * @param bool $force
+ *   (optional)
+ *
+ * @return
+ *
+ */
 function biblio_delete_orphan_keywords ($force = FALSE) {
   if (variable_get('biblio_keyword_orphan_autoclean', 0) || $force) {
     $active_kids = array();
@@ -97,12 +112,13 @@ function biblio_delete_orphan_keywords ($force = FALSE) {
 }
 
 /**
- * Load keywords from the database
+ * Loads keywords from the database based on node revision ID.
  *
  * @param $vid
- *   node version id of the keywords to load
+ *   node version id of the keywords to load.
+ *
  * @return
- *   an array of keywords keyed on the keyword id
+ *   An array of keywords keyed on the node revision ID.
  */
 function biblio_load_keywords($vid) {
 
@@ -116,8 +132,13 @@ function biblio_load_keywords($vid) {
 }
 
 /**
+ *
+ *
  * @param $node
+ *
+ *
  * @return
+ *
  */
 function biblio_insert_keywords($node, $update = FALSE) {
   $kw_vocab = variable_get('biblio_keyword_vocabulary', 0);
@@ -194,9 +215,15 @@ function biblio_insert_keywords($node, $update = FALSE) {
 
   return ;
 }
+
 /**
+ *
+ *
  * @param $word
+ *
+ *
  * @return
+ *
  */
 function biblio_save_keyword(&$keyword) {
   if (!empty($keyword['kid']) && $keyword['word']) {
@@ -211,16 +238,26 @@ function biblio_save_keyword(&$keyword) {
 }
 
 /**
+ *
+ *
  * @param $node
+ *
+ *
  * @return none
+ *
  */
 function biblio_delete_node_keywords($node) {
   db_query('DELETE FROM {biblio_keyword} WHERE nid = %d', $node->nid);
 }
 
 /**
+ *
+ *
  * @param $node
+ *
+ *
  * @return none
+ *
  */
 function biblio_delete_revision_keywords($node) {
   db_query('DELETE FROM {biblio_keyword} WHERE vid = %d', $node->vid);
@@ -229,13 +266,16 @@ function biblio_delete_revision_keywords($node) {
 }
 
 /**
+ *
+ *
  * Delete multiple keywords from both the biblio_keyword and biblio_keyword_data tables
  * This will remove the keywords referenced by the supplied ID's from ALL nodes which reference them.
  *
  * @param array $keywords
- *   An array of keyword id's to delete
- * @return
- *   The number of keywords deleted
+ *   An array of (integer) keyword IDs to delete.
+ *
+ * @return integer
+ *   The number of keywords deleted.
  */
 function biblio_delete_multiple_keywords($keywords) {
   $count = 0;
@@ -244,14 +284,18 @@ function biblio_delete_multiple_keywords($keywords) {
   }
   return $count;
 }
+
 /**
+ *
+ *
  * Delete a keyword from both the biblio_keyword and biblio_keyword_data tables
  * This will remove the keyword referenced by the supplied ID from ALL nodes which reference them.
  *
- * @param $keyword_id
- *   The keyword id to delete
- * @return
- *   The number of keywords deleted (should always be one)
+ * @param integer $keyword_id
+ *   The keyword ID to delete.
+ *
+ * @return integer
+ *   The number of keywords deleted (should always be one).
  */
 function biblio_delete_keyword($keyword_id) {
   db_query('DELETE FROM {biblio_keyword} WHERE kid = %d', $keyword_id);
@@ -259,6 +303,17 @@ function biblio_delete_keyword($keyword_id) {
   return db_affected_rows();
 }
 
+/**
+ *
+ *
+ * @param $string
+ *
+ * @param $sep
+ *   (optional)
+ *
+ * @return none
+ *
+ */
 function biblio_explode_keywords($string, $sep = NULL) {
   if (!$sep) {
     $sep = check_plain(variable_get('biblio_keyword_sep', ','));
@@ -279,8 +334,19 @@ function biblio_explode_keywords($string, $sep = NULL) {
   }
   return $keywords;
 }
-function biblio_implode_keywords($keywords, $sep = '') {
 
+/**
+ *
+ *
+ * @param $keywords
+ *
+ * @param $sep
+ *   (optional)
+ *
+ * @return string
+ *
+ */
+function biblio_implode_keywords($keywords, $sep = '') {
   if (empty($sep)) $sep = check_plain(variable_get('biblio_keyword_sep', ','));
   $string = '';
   foreach ($keywords as $kid => $keyword) {
@@ -293,4 +359,4 @@ function biblio_implode_keywords($keywords, $sep = '') {
     }
   }
   return $string;
-}
\ No newline at end of file
+}
diff --git a/includes/biblio.pages.inc b/includes/biblio.pages.inc
index 4b9f8eb..73d9193 100644
--- a/includes/biblio.pages.inc
+++ b/includes/biblio.pages.inc
@@ -1,25 +1,7 @@
-<?PHP
+<?php
 /**
  * @file
  * Functions in the biblio module related to filtering and page generation.
- *
- *
- * Copyright (C) 2006-2008  Ron Jerome
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 
 /**
@@ -99,50 +81,68 @@ function biblio_db_search() {
         }
       }
       // Wrong query (too short, only negative words etc.). Warning has been issued.
-      else $_SESSION['biblio_filter'] = array();
+      else {
+        $_SESSION['biblio_filter'] = array();
+      }
     }
   }
 
   $inline = in_array('inline', $arg_list);
-  $inline = in_array('profile', $arg_list)?'profile':$inline;
+  $inline = in_array('profile', $arg_list) ? 'profile' : $inline;
 
   $query_info = biblio_build_query($arg_list);
-  if ($query_info['rss']['feed']){
+  // If desired, prepare a listing in rss feed format which will print directly
+  // to the screen with no return value.
+  if ($query_info['rss']['feed']) {
     biblio_filter_feed($query_info['query'], $query_info['query_terms'], $query_info['rss']);
+    return;
   }
-  else{
-    //$count = db_result(db_query($query_info['count_query'],$query_info['query_terms']));
-    $nodes = array();
-    $result = pager_query($query_info['query'], variable_get('biblio_rowsperpage', 25),0,$query_info['count_query'],$query_info['query_terms']);
-    $query_info['filter_line'] = _biblio_filter_info_line($query_info['args']);
-
-    while ($res = db_fetch_array($result)) {
-      $node = node_load($res['nid']);
-      foreach($res as $key => $value) {
-        if (!isset($node->$key)) {
-          $node->$key = $value;
-        }
+
+  // Prepare an HTML formatted string for display in browser.
+  $nodes = array();
+  $result = pager_query($query_info['query'], variable_get('biblio_rowsperpage', 25), 0, $query_info['count_query'], $query_info['query_terms']);
+  $query_info['filter_line'] = _biblio_filter_info_line($query_info['args']);
+
+  while ($res = db_fetch_array($result)) {
+    $node = node_load($res['nid']);
+    foreach($res as $key => $value) {
+      if (!isset($node->$key)) {
+        $node->$key = $value;
       }
-      $nodes[] = $node;
     }
-
-    return biblio_show_results($nodes, $query_info, $inline);
+    $nodes[] = $node;
   }
-
+  return biblio_show_results($nodes, $query_info, $inline);
 }
-/*
+
+/**
+ * Creates an SQL query to select and order biblio type content.
+ *
  * biblio_db_search builds the SQL query which will be used to
  * select and order "biblio" type nodes.  The query results are
  * then passed to biblio_show_results for output
  *
+ * @param $arg_list
+ *
  *
+ * @return array
+ *   An associative array with the following keys:
+ *   - query:
+ *   - query_terms:
+ *   - count_query:
+ *   - args:
+ *   - sort_attrib:
+ *   - rss:
  */
 function biblio_build_query($arg_list) {
   global $user, $db_type;
-  static $bcc = 0; //biblio_contributor (bc) count , increase for every invocation
+  // Count of biblio_contributor (bc), increases with each invocation.
+  static $bcc = 0;
   static $bkd = 0;
-  static $tcc = 0; //term counter, increase for every invocation
-  $inline = $rss_info['feed'] = false;
+  // Count of terms, increase with every invocation.
+  static $tcc = 0;
+
+  $inline = $rss_info['feed'] = FALSE;
   $joins = array();
   $selects = array();
   $count_selects = array();
@@ -190,31 +190,51 @@ function biblio_build_query($arg_list) {
 
   if (count($arg_list) ) {
     $args = array();
+
+    // Initialize various counters and variables
+    $bkd = 0;
+    $operator = '';
+
     while ($arg_list) {
       $type = $arg_list[0];
       array_shift($arg_list);
+      // The default operator is AND.
+      $operator = empty($operator) ? " AND " : $operator;
       switch ($type) {
         case 'no_filters':
           break;
+
+        case 'and':
+          $operator = " AND ";
+          break;
+
+        case 'or':
+          $operator = " OR ";
+          break;
+
         case 'inline':
-          $inline = true;
+          $inline = TRUE;
           break;
+
         case 'rss.xml':
-          $rss_info['feed'] = true;
-          $count_limit = 'LIMIT '. variable_get('biblio_rss_number_of_entries', 10);
+          $rss_info['feed'] = TRUE;
+          $count_limit = 'LIMIT ' . variable_get('biblio_rss_number_of_entries', 10);
           break;
+
         case 'profile':
           $inline = "profile";
           break;
+
         case 'cid':
         case 'aid':
           $bcc++;
           $term = explode("?",array_shift($arg_list));
-          $joins[] = "inner join {biblio_contributor} as bc". $bcc ." on n.vid = bc". $bcc .".vid";
-          $where[] = "bc". $bcc .".cid = '%d' ";
+          $joins[] = "inner join {biblio_contributor} as bc" . $bcc . " on n.vid = bc" . $bcc . ".vid";
+          $where[] = "bc" . $bcc . ".cid = '%d' ";
           $terms[] = db_escape_string($term[0]);
           array_push($args, $type, $term[0]);
           break;
+
         case 'term':
         case 'term_id':
           $term = explode("?",array_shift($arg_list));
@@ -229,12 +249,14 @@ function biblio_build_query($arg_list) {
           array_push($args, $type, $term[0]);
           $tcc++;
           break;
+
         case 'tg':
           $term = explode("?",array_shift($arg_list));
           $where[] = "substring($sort_title,1 ,1)" . $match_op . " LOWER('%s')";
           $terms[] = db_escape_string($term[0]);
           array_push($args, $type, $term[0]);
           break;
+
         case 'ag': //selects entries whoose authors firstname starts with the letter provided
           $term = explode("?",array_shift($arg_list));
           $where[] = " UPPER(substring(bcd.lastname,1,1)) = '%s' ";
@@ -244,6 +266,7 @@ function biblio_build_query($arg_list) {
           $terms[] = db_escape_string(strtoupper($term[0]));
           array_push($args, $type, $term[0]);
           break;
+
         case 'author':
           $bcc++;
           $term = explode("?",array_shift($arg_list));
@@ -270,12 +293,14 @@ function biblio_build_query($arg_list) {
           }
           array_push($args, $type, $term[0]);
           break;
+
         case 'publisher':
           $term = explode("?",array_shift($arg_list));
           $where[] = "b.biblio_publisher ". $match_op ." '%s' ";
           $terms[] = db_escape_string($term[0]);
           array_push($args, $type, $term[0]);
           break;
+
         case 'year':
           $term = db_escape_string(array_shift($arg_list));
           $where[] = "b.biblio_year=%d ";
@@ -283,6 +308,7 @@ function biblio_build_query($arg_list) {
           $terms[] = (int)$term;
           array_push($args, $type, (int)$term);
           break;
+
         case 'uid':
           $term = db_escape_string(array_shift($arg_list));
           $where[] = "n.uid=%d ";
@@ -290,6 +316,7 @@ function biblio_build_query($arg_list) {
           $terms[] = (int)$term;
           array_push($args, $type, (int)$term);
           break;
+
         case 'keyword':
           $bkd++;
           $term = explode("?",array_shift($arg_list));
@@ -318,12 +345,14 @@ function biblio_build_query($arg_list) {
           }
           array_push($args, $type, $term[0]);
           break;
+
         case 'citekey':
           $term = explode("?",array_shift($arg_list));
           $terms[] = db_escape_string($term[0]);
           $where[] = "b.biblio_citekey= '%s' ";
           array_push($args, $type, $term[0]);
           break;
+
         case 'type':
           $term = db_escape_string(array_shift($arg_list));
           $where[] = "b.biblio_type=%d ";
@@ -331,10 +360,12 @@ function biblio_build_query($arg_list) {
           $terms[] = (int)$term;
           array_push($args, $type, (int)$term);
           break;
+
         case 'order':
           $term = (db_escape_string(strtolower(array_shift($arg_list))) == 'desc')?'desc':'asc';
           $sort_attrib['order'] = $term;
           break;
+
         case 'sort':
           $term = db_escape_string(array_shift($arg_list));
           $sort_attrib['sort'] = $term;
@@ -343,10 +374,12 @@ function biblio_build_query($arg_list) {
               $sortby = "ORDER BY bt.name %s, $sort_title";
               $selects[] = "bt.name, $sort_title";
               break;
+
             case 'title':
               $sortby = "ORDER BY $sort_title %s";
               $selects[] = $sort_title;
               break;
+
             case 'author':
               $sortby = "ORDER BY bcd.lastname %s ";
               $where['bc-rank'] = "bc.rank=0";
@@ -355,6 +388,7 @@ function biblio_build_query($arg_list) {
               $joins['bcd'] = '  JOIN {biblio_contributor_data} as bcd on bc.cid = bcd.cid ';
               $selects[] = "bcd.lastname";
               break;
+
             case 'keyword': // added msh 070808
               $sortby = "ORDER BY bkd.word %s ";
               $joins['bk'] = '  JOIN {biblio_keyword} as bk on b.vid = bk.vid ';
@@ -362,6 +396,7 @@ function biblio_build_query($arg_list) {
               $selects[] = "bkd.word as biblio_keyword";
               //$count_selects[] = "bkd.word";
               break;
+
             case 'year':
             default:
               $sortby = "ORDER BY b.biblio_year %s, b.biblio_date %s, $sort_title %s";
@@ -369,28 +404,29 @@ function biblio_build_query($arg_list) {
               $selects[] = $sort_title;
           } //end switch
           break;
+
         case 'search':
           $term = explode("?",array_shift($arg_list));
-              $result_nids = split(',', $term[0]);
-              $where[] = "n.nid in (".db_placeholders($result_nids).")";
-              foreach ($result_nids as $result_nid) {
-                $terms[] = db_escape_string($result_nid);
-                array_push($args, $type, $result_nid);
-              }
-        // Save search keyword to show in the filter list.
-              $term = array_shift($arg_list);
-              array_push($args, $type, $term);
-              break;
-            default:
-              $fields = biblio_get_db_fields();
-              $term = explode("?",array_shift($arg_list));
-              if (in_array("biblio_$type",$fields))
-              {
-                $where[] = "b.biblio_$type ".$match_op ." '%s' ";
-                $terms[] = db_escape_string($term[0]);
-                array_push($args, $type, $term[0]);
-              }
-              break;
+          $result_nids = split(',', $term[0]);
+          $where[] = "n.nid in (".db_placeholders($result_nids).")";
+          foreach ($result_nids as $result_nid) {
+            $terms[] = db_escape_string($result_nid);
+            array_push($args, $type, $result_nid);
+          }
+          // Save search keyword to show in the filter list.
+          $term = array_shift($arg_list);
+          array_push($args, $type, $term);
+          break;
+
+        default:
+          $fields = biblio_get_db_fields();
+          $term = explode("?",array_shift($arg_list));
+          if (in_array("biblio_$type",$fields)) {
+            $where[] = "b.biblio_$type ".$match_op ." '%s' ";
+            $terms[] = db_escape_string($term[0]);
+            array_push($args, $type, $term[0]);
+          }
+          break;
       }
     }
   }
@@ -603,9 +639,23 @@ function _biblio_sort_tabs($attrib, $options = NULL) {
   return $content;
 }
 
+/**
+ * Page callback: Creates ...
+ *
+ * @param array $tab
+ *   An associative array with the following elements:
+ *   - text:
+ *   - arrow:
+ *   - attributes: An array with an optional class key.
+ * @param bool $tabs
+ *   (optional)
+ *
+ * @return string
+ *
+ */
 function _biblio_sort_tab($tab, $tabs = FALSE) {
   if ($tabs) {
-    $text  = '<span class="a"><span class="b">'.$tab['text'].$tab['arrow'].'</span></span>';
+    $text  = '<span class="a"><span class="b">' . $tab['text'] . $tab['arrow'] . '</span></span>';
     $class = (isset($tab['attributes']['class'])) ? 'class="active"' : '';
     $link  = l($text, $tab['path'], $tab);
     return "<li $class >" . str_replace('class="active"', $class, $link) . '</li>';
@@ -613,9 +663,17 @@ function _biblio_sort_tab($tab, $tabs = FALSE) {
   else {
     return $tab['pfx']. l($tab['text'], $tab['path'], $tab) . $tab['arrow'] . $tab['sfx'];
   }
-  return;
 }
 
+/**
+ *
+ *
+ * @param $args
+ *
+ *
+ * @return string
+ *
+ */
 function _biblio_filter_info_line($args) {
   module_load_include('inc', 'biblio', 'includes/biblio.contributors');
   $content = '';
@@ -709,6 +767,19 @@ function _biblio_filter_info_line($args) {
   return $content;
 }
 
+/**
+ *
+ *
+ * @param $attrib
+ *
+ * @param $node
+ *
+ * @param bool $reset
+ *   (optional)
+ *
+ * @return string
+ *
+ */
 function _biblio_category_separator_bar($attrib, $node, $reset = FALSE) {
   static $_text = '';
   if ($reset) { $_text = ''; return;}
@@ -783,6 +854,9 @@ function _biblio_category_separator_bar($attrib, $node, $reset = FALSE) {
  *
  * @param string $text
  *
+ *
+ * @return string
+ *
  */
 function theme_biblio_separator_bar($text) {
   $content = "\n".'<div class="biblio-separator-bar">' . check_plain($text) . "</div>\n";
@@ -792,6 +866,9 @@ function theme_biblio_separator_bar($text) {
 
 /**
  * Returns HTML for end of a biblio category section.
+ *
+ * @return string
+ *
  */
 function theme_biblio_end_category_section() {
   return "\n</div><!-- end category-section -->";
@@ -886,6 +963,8 @@ function biblio_build_search_query($keys = '') {
  * In biblio_db_search, we fill the second component with the list of nids
  * matching our keywords, as returned by node_search.  We store the keywords
  * only for showing them in "Search results for <keywords>".
+ *
+ * @informs
  */
 function biblio_search_form_submit($form, &$form_state) {
   $keys = $form_state['values']['keys'];
@@ -952,7 +1031,7 @@ function _get_biblio_filters() {
   $pub_type[0] = '';
   $pub_taxo[0] = '';
   $pub_keywords[0] = '';
-  
+
   $fields = " b.biblio_year, t.name , t.tid ";
   $order = " b.biblio_year DESC";
   $taxo_fields = "td.name as termname,td.tid as taxid, v.name as vocab_name";
@@ -1136,7 +1215,7 @@ function biblio_get_user_pubs($user, $profile = '', $nofilters = '') {
  *
  *
  * @return string
- *   An HTML formatted string for inline style of biblio content view. 
+ *   An HTML formatted string for inline style of biblio content view.
  */
 function biblio_view_inline(&$node) {
   $style = biblio_get_style();
@@ -1151,7 +1230,7 @@ function biblio_view_inline(&$node) {
 
 /**
  * Creates a view based upon a cititaion key.
- * 
+ *
  * @return string
  *
  */
@@ -1161,7 +1240,7 @@ function biblio_citekey_view() {
   if ($nid->nid > 0) {
     $node = node_load($nid->nid);
     return node_page_view($node);
-  } 
+  }
   else {
     return t("Sorry, citekey @cite not found", array('@cite'=>$citekey));
   }
@@ -1181,7 +1260,7 @@ function biblio_citekey_view() {
 function _biblio_keyword_links($keywords, $base = 'biblio') {
   $options = array();
   $options['query'] = '';
-  
+
   if (isset($_GET['sort'])) {
     $options['query'] = "sort=" . $_GET['sort'];
   }
@@ -1203,6 +1282,15 @@ function _biblio_keyword_links($keywords, $base = 'biblio') {
   return $html;
 }
 
+/**
+ *
+ *
+ * @param bool $filter
+ *   (optional)
+ *
+ * @return
+ *
+ */
 function biblio_author_page($filter = NULL) {
   $path = drupal_get_path('module', 'biblio');
   drupal_add_js($path . '/misc/biblio.highlight.js');
@@ -1211,6 +1299,15 @@ function biblio_author_page($filter = NULL) {
   return _biblio_format_author_page($filter, $authors);
 }
 
+/**
+ *
+ *
+ * @param bool $filter
+ *   (optional)
+ *
+ * @return array
+ *
+ */
 function _biblio_get_authors($filter = NULL) {
   global $user;
   $where = array();
@@ -1254,7 +1351,7 @@ function _biblio_get_authors($filter = NULL) {
     $suspects[] = $author->lastname;
   }
 
-  $sql = 'SELECT bd.cid, bd.drupal_uid, bd.name, bd.lastname, bd.firstname, bd.prefix, ' . 
+  $sql = 'SELECT bd.cid, bd.drupal_uid, bd.name, bd.lastname, bd.firstname, bd.prefix, ' .
            'bd.suffix, bd.initials, bd.affiliation, bd.md5, bd.literal, COUNT(*) AS cnt ' .
          'FROM {biblio_contributor} b ' .
            'LEFT JOIN {biblio_contributor_data} bd ON b.cid = bd.cid ' .
@@ -1319,7 +1416,7 @@ function _biblio_format_author_page($filter, $authors) {
 }
 
 /*
- * Formats the authors as HTML and adds edit links if desired. 
+ * Formats the authors as HTML and adds edit links if desired.
  *
  * Helper function to format the authors and add edit links if required.
  *
@@ -1343,6 +1440,14 @@ function _biblio_format_author($author) {
   return $format;
 }
 
+/**
+ *
+ *
+ * @param $author
+ *
+ *
+ * @return
+ */
 function _biblio_author_edit_links($author) {
   static $path = '';
   if (empty($path)){
@@ -1352,22 +1457,42 @@ function _biblio_author_edit_links($author) {
   return l(' ['.t('edit').']', $path . $author['cid'] ."/edit/" );
 }
 
+/**
+ *
+ *
+ * @param bool $filter
+ *   (optional)
+ *
+ * @return
+ *
+ */
 function biblio_keyword_page($filter = NULL) {
   $keywords = _biblio_get_keywords($filter);
   return _biblio_format_keyword_page($filter, $keywords);
 }
 
+/**
+ *
+ *
+ * @param bool $filter
+ *   (optional)
+ *
+ * @return
+ *
+ */
 function _biblio_get_keywords($filter = NULL) {
   global $user;
+  $keywords = array();
   $where = array();
   $where_clause = '';
+  
   if ($filter) {
     $filter = strtoupper($filter);
     $where[] =  "UPPER(SUBSTRING(word,1,1)) = '%s' ";
-    $header_ext = t(' (which start with the letter "@letter") ',array('@letter' => $filter ));
+    $header_ext = t(' (which start with the letter "@letter") ', array('@letter' => $filter ));
   }
   else {
-    $query_ext =  NULL;
+    $query_ext = NULL;
     $header_ext = NULL;
   }
 
@@ -1396,6 +1521,17 @@ function _biblio_get_keywords($filter = NULL) {
   return $keywords;
 }
 
+/**
+ *
+ *
+ * @param $filter
+ *
+ * @param $keywords
+ *
+ *
+ * @return
+ *
+ */
 function _biblio_format_keyword_page($filter, $keywords) {
   $header = array();
   $rows = array();
@@ -1411,6 +1547,16 @@ function _biblio_format_keyword_page($filter, $keywords) {
   $output .= theme('table', $header, $rows);
   return $output;
 }
+
+/**
+ *
+ *
+ * @param $keyword
+ *
+ *
+ * @return
+ *
+ */
 function _biblio_format_keyword($keyword) {
   $base      = variable_get('biblio_base', 'biblio');
   $format    = l(trim($keyword->word), "$base/keyword/$keyword->kid" );
diff --git a/includes/biblio.tokens.inc b/includes/biblio.tokens.inc
index f504ae5..4e9171a 100644
--- a/includes/biblio.tokens.inc
+++ b/includes/biblio.tokens.inc
@@ -1,4 +1,18 @@
 <?php
+/**
+ * @file
+ *
+ */
+
+/**
+ *
+ *
+ * @param string $type
+ *   (optional)
+ *
+ * @return
+ *
+ */
 function _biblio_token_list($type = 'all') {
   if ($type == 'node') {
     $tokens['node']['biblio_year']      = t("Biblio: Publication year");
@@ -11,7 +25,7 @@ function _biblio_token_list($type = 'all') {
 }
 
 /**
- * Implementation of hook_token_values() for og specific tokens
+ * Implements hook_token_values() for Organic Group specific tokens.
  */
 function _biblio_token_values($type, $object = NULL) {
   switch ($type) {
@@ -29,4 +43,3 @@ function _biblio_token_values($type, $object = NULL) {
       break;
   }
 }
-
diff --git a/includes/biblio.util.inc b/includes/biblio.util.inc
index 0f0792c..ad4ee6c 100644
--- a/includes/biblio.util.inc
+++ b/includes/biblio.util.inc
@@ -1,4 +1,18 @@
 <?php
+/**
+ * @file
+ *
+ */
+
+/**
+ *
+ *
+ * @param string $title
+ *   
+ *
+ * @return
+ *
+ */
 function biblio_normalize_title($title) {
   $stop_words = 'a,an,the,is,on';
   $stop_words = explode(',', variable_get('biblio_stop_words', $stop_words));
@@ -19,6 +33,16 @@ function biblio_normalize_title($title) {
   }
   return drupal_substr(implode(' ', $title_words), 0, 64);
 }
+
+/**
+ *
+ *
+ * @param string $title
+ *   
+ *
+ * @return
+ *
+ */
 function biblio_coins($node) {
   // Copyright:          Matthias Steffens <mailto:refbase@extracts.de> and the file's
   //                     original author.
@@ -54,6 +78,15 @@ function biblio_coins($node) {
   return $coinsSpan;
 }
 
+/**
+ *
+ *
+ * @param string $title
+ *   
+ *
+ * @return
+ *
+ */
 function biblio_contextObject($node) {
   // Copyright:          Matthias Steffens <mailto:refbase@extracts.de> and the file's
   //                     original author.
@@ -161,6 +194,15 @@ function biblio_contextObject($node) {
   return $co;
 }
 
+/**
+ *
+ *
+ * @param string $title
+ *   
+ *
+ * @return
+ *
+ */
 function biblio_coins_generate(& $node) {
   if (!isset($node->vid)) {
     $node->biblio_coins = biblio_coins($node);
@@ -190,6 +232,15 @@ function biblio_coins_generate(& $node) {
   }
 }
 
+/**
+ *
+ *
+ * @param string $title
+ *   
+ *
+ * @return
+ *
+ */
 function _strip_punctuation($text) {
   return preg_replace("/[[:punct:]]/", '', $text);
 }
@@ -227,8 +278,7 @@ function _strip_punctuation($text) {
  * See also:
  * 	http://nadeausoftware.com/articles/2007/9/php_tip_how_strip_punctuation_characters_web_page
  */
-function _strip_punctuation_utf8( $text )
-{
+function _strip_punctuation_utf8($text) {
 	$urlbrackets    = '\[\]\(\)';
 	$urlspacebefore = ':;\'_\*%@&?!' . $urlbrackets;
 	$urlspaceafter  = '\.,:;\'\-_\*@&\/\\\\\?!#' . $urlbrackets;
@@ -299,8 +349,7 @@ function _strip_punctuation_utf8( $text )
  * See also:
  *	http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_symbol_characters_web_page
  */
-function _strip_symbols( $text )
-{
+function _strip_symbols($text) {
 	$plus   = '\+\x{FE62}\x{FF0B}\x{208A}\x{207A}';
 	$minus  = '\x{2012}\x{208B}\x{207B}';
 
@@ -341,13 +390,13 @@ function _strip_symbols( $text )
 		' ',
 		$text );
 }
+
 /**
  * Remove HTML tags, including invisible text such as style and
  * script code, and embedded objects.  Add line breaks around
  * block-level tags to prevent word joining after tag removal.
  */
-function _strip_html_tags( $text )
-{
+function _strip_html_tags($text) {
     $text = preg_replace(
         array(
           // Remove invisible content
@@ -375,5 +424,5 @@ function _strip_html_tags( $text )
             "\n\$0", "\n\$0",
         ),
         $text );
-    return strip_tags( $text );
-}
\ No newline at end of file
+  return strip_tags( $text );
+}
diff --git a/includes/biblio_theme.inc b/includes/biblio_theme.inc
index 7bb9eec..decbd3c 100644
--- a/includes/biblio_theme.inc
+++ b/includes/biblio_theme.inc
@@ -1,44 +1,37 @@
 <?php
 /**
+ * @file
  *
- *   Copyright (C) 2006-2008  Ron Jerome
+ */
+
+module_load_include('inc', 'biblio', 'includes/biblio.pages');
+
+/**
  *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * @param array $element
  *
- *   You should have received a copy of the GNU General Public License along
- *   with this program; if not, write to the Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- ****************************************************************************/
-module_load_include('inc','biblio','includes/biblio.pages');
-
-/**
- * @param $element
- * @return unknown_type
+ * @ingroup themeable
  */
 function theme_biblio_coin_button($element) {
-  return '<a href="/biblio/regen_coins"><input type="button"  name="'. $element['#name'] .'" value="'. $element['#value'] .'"  /></a>';
+  return '<a href="/biblio/regen_coins"><input type="button"  name="' . $element['#name'] . '" value="' . $element['#value'] . '"  /></a>';
 }
 
 /**
- * @param $openURL
- * @return unknown_type
+ *
+ *
+ * @param object $node
+ *
+ *
+ * @ingroup themeable
  */
 function theme_biblio_openurl($node) {
   global $user;
   $openURLResolver = '';
   if (isset($user->biblio_baseopenurl)  &&
       !empty($user->biblio_baseopenurl) &&
-      variable_get('biblio_show_openurl_profile_form', '1'))
-  {
+      variable_get('biblio_show_openurl_profile_form', '1')) {
     $openURLResolver = $user->biblio_baseopenurl;
   }
   else {
@@ -55,7 +48,7 @@ function theme_biblio_openurl($node) {
         'href'       => $openURLResolver,
         'html'       => TRUE,
         'attributes' => array(
-          'class'      => 'biblio-openurl-image',
+          'class'    => 'biblio-openurl-image',
         ),
         'query'      => $openurl_query_options,
       );
@@ -65,7 +58,7 @@ function theme_biblio_openurl($node) {
         'title'      => t('Find It Via OpenURL!'),
         'href'       => $openURLResolver,
         'attributes' => array(
-          'class'      => 'biblio-openurl-text',
+          'class'    => 'biblio-openurl-text',
         ),
         'query'      => $openurl_query_options,
       );
@@ -75,8 +68,13 @@ function theme_biblio_openurl($node) {
 }
 
 /**
- * @param $node
- * @return unknown_type
+ *
+ *
+ * @param object $node
+ *
+ *
+ * @return array
+ *
  */
 function biblio_openURL($node) {
   $query = array();
@@ -102,14 +100,20 @@ function biblio_openURL($node) {
   return $query;
 }
 
-
 /**
+ *
+ *
  * DEPRECIATED! this was the original output format which is not to flexable it will be removed
  * TODO: remove this function
+ *
  * @param $node
+ *
  * @param $base
+ *
  * @param $style
- * @return unknown_type
+ *
+ *
+ * @ingroup themeable
  */
 function theme_biblio_long($node, $base = 'biblio', $style = 'classic') {
   if (module_exists('popups')){
@@ -210,11 +214,18 @@ function theme_biblio_long($node, $base = 'biblio', $style = 'classic') {
 
   return $output;
 }
+
 /**
- * @param $node
- * @param $base
+ *
+ *
+ * @param object $node
+ *   A node object
+ * @param string $base
+ *
  * @param $teaser
- * @return unknown_type
+ *
+ *
+ * @ingroup themeable
  */
 function theme_biblio_tabular($node, $base = 'biblio', $teaser = false) {
   static $citeproc;
@@ -308,29 +319,60 @@ function theme_biblio_tabular($node, $base = 'biblio', $teaser = false) {
   return $output;
 }
 
+/**
+ *
+ *
+ * @param array $contributors
+ *
+ * @param string $style
+ *   (optional)
+ * @param integer $cat
+ *   (optional)
+ * @param bool $inline
+ *   (optional)
+ * @param string $glue
+ *   (optional)
+ *
+ * @ingroup themeable
+ */
 function theme_biblio_authors($contributors, $style = 'classic', $cat = 1, $inline = false, $glue = ', ') {
-  if (empty($contributors)) return; // t('No author information available');
-  $author_style_function = '_'.$style.'_format_author';
+  // Immediately return if there are no contributors
+  if (empty($contributors)) {
+    // @todo: Shouldn't this return any empty string?
+    return;
+  }
+  $author_style_function = '_' . $style . '_format_author';
   $author_links = variable_get('biblio_author_links', 1);
   $base  = variable_get('biblio_base', 'biblio');
   foreach ($contributors as $key => $author) {
     if (!empty($author['name']) && !isset($author['lastname'])) {
-      $author = biblio_parse_author($author, $cat); // this is needed for form preview to fill in all fields
+      // This is needed for form preview to fill in all fields.
+      $author = biblio_parse_author($author, $cat);
     }
     if (strlen($author['name'])) {
       $$author['name'] = $author_style_function($author);
       if ($author_links) $format = theme('biblio_author_link', $author);
-      // add the auth_type as css id to allow later formatting
-      $author_array[] = '<span id="'.$author['auth_type'].'">'.$format.'</span>';
+      // Add the auth_type as css ID to allow later formatting.
+      $author_array[] = '<span id="' . $author['auth_type'] . '">' . $format . '</span>';
     }
   }
-  if (empty($author_array)) return '';
+  if (empty($author_array)) {
+    return '';
+  }
 
   $output  = '<span class="biblio_authors">';
   $output .= implode($glue, $author_array);
   $output .= '</span>';
   return $output;
 }
+
+/**
+ *
+ *
+ *
+ * @return array
+ *
+ */
 function _biblio_get_latin1_regex() {
   $alnum = "[:alnum:]ÄÅÁÀÂÃÇÉÈÊËÑÖØÓÒÔÕÜÚÙÛÍÌÎÏÆäåáàâãçéèêëñöøóòôõüúùûíìîïæÿß";
 
@@ -375,8 +417,12 @@ function _biblio_get_latin1_regex() {
        $print, $punct, $space, $upper, $word, $patternModifiers);
 
 }
+
 /*
  * Helper function for theme_biblio_format_authors() and theme_biblio_page_number()
+ *
+ * @return array
+ *
  */
 function _biblio_get_utf8_regex() {
 
@@ -424,6 +470,12 @@ function _biblio_get_utf8_regex() {
        $print, $punct, $space, $upper, $word, $patternModifiers);
 }
 
+/**
+ *
+ *
+ * @return array
+ *
+ */
 function _biblio_get_regex_patterns() {
   // Checks if PCRE is compiled with UTF-8 and Unicode support
   if (!@preg_match('/\pL/u', 'a')) {
@@ -435,6 +487,15 @@ function _biblio_get_regex_patterns() {
   }
 }
 
+/**
+ *
+ *
+ * @param array $authors
+ *
+ *
+ * @return string
+ *
+ */
 function biblio_format_authors($authors) {
   if (module_exists('biblio_citeproc')) {
     static $auth_proc;
@@ -450,7 +511,7 @@ function biblio_format_authors($authors) {
       $csl_doc->loadXML($csl);
       $auth_proc = new csl_rendering_element($csl_doc);
     }
-    return $auth_proc->render($authors);
+    $output = $auth_proc->render($authors);
   }
   else {
     $style_name = biblio_get_style();
@@ -459,36 +520,52 @@ function biblio_format_authors($authors) {
       module_load_include('inc', 'biblio', "styles/biblio_style_$style_name");
     }
     $author_options = $style_function();
-    $author_options['numberOfAuthorsTriggeringEtAl'] = 100; //set really high so we see all authors
-    return theme('biblio_format_authors',  $authors, $author_options);
+    // Set to really high value so we will see all authors.
+    $author_options['numberOfAuthorsTriggeringEtAl'] = 100;
+    $output = theme('biblio_format_authors',  $authors, $author_options);
   }
-
-  return;
+  return $output;
 }
 
-function theme_biblio_format_authors($contributors, $options, $inline = false)
-{
+/**
+ *
+ *
+ * @param array $contributors
+ *
+ * @param array $options
+ *
+ * @param bool $inline
+ *
+ *
+ * @ingroup themeable
+ */
+function theme_biblio_format_authors($contributors, $options, $inline = FALSE) {
   if (empty($contributors)) return;
   list($alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower,
        $print, $punct, $space, $upper, $word, $patternModifiers) = _biblio_get_regex_patterns();
   $base  = variable_get('biblio_base', 'biblio');
   $author_links = variable_get('biblio_author_links', 1);
 
-  $authorCount = count($contributors); // check how many authors we have to deal with
-  $output = ""; // this variable will hold the final author string
-  $includeStringAfterFirstAuthor = false;
+  // Determine how many authors we have to process.
+  $authorCount = count($contributors);
+  // This variable will hold the final author string.
+  $output = "";
+  $includeStringAfterFirstAuthor = FALSE;
 
-  if (empty($options['numberOfAuthorsTriggeringEtAl']))  $options['numberOfAuthorsTriggeringEtAl'] = $authorCount;
-
-  if (empty($options['includeNumberOfAuthors']))  $options['includeNumberOfAuthors'] = $authorCount;
+  if (empty($options['numberOfAuthorsTriggeringEtAl'])) {
+    $options['numberOfAuthorsTriggeringEtAl'] = $authorCount;
+  }
+  if (empty($options['includeNumberOfAuthors'])) {
+    $options['includeNumberOfAuthors'] = $authorCount;
+  }
 
-  foreach($contributors as $rank => $author)
-  {
+  foreach($contributors as $rank => $author) {
     if (empty($author['name'])) continue;
     if (empty($author['literal'])) {
       if (!isset($author['lastname'])) {
-        module_load_include('inc','biblio','includes/biblio.contributors');
-        $author = biblio_parse_author($author, $author['auth_type']); // this is needed for form preview to fill in all fields
+        module_load_include('inc', 'biblio', 'includes/biblio.contributors');
+        // This is needed for form preview to fill in all fields.
+        $author = biblio_parse_author($author, $author['auth_type']);
       }
 
       if (!empty($author['firstname'])) {
@@ -563,8 +640,7 @@ function theme_biblio_format_authors($contributors, $options, $inline = false)
     }
   }
   if ($author_links) {
-
-      $author['name'] = theme('biblio_author_link', $author);
+    $author['name'] = theme('biblio_author_link', $author);
     }
     else {
       $author['name'] = check_plain($author['name']);
@@ -605,18 +681,18 @@ function theme_biblio_format_authors($contributors, $options, $inline = false)
 
   return $output;
 }
-/**
- * Returns HTML for an author link.
- *
- * @param array $author
- *   An associative array with information about an author including elements:
- *   - name: A string with the author's name.
- *   - cid: An integer identifying the author in biblio module.
- *   - drupal_uid: (optional) An integer linking to Drupal user ID.
- *
- * @ingroup themeable
- */
 
+/**
+ * Returns HTML for an author link.
+ *
+ * @param array $author
+ *   An associative array with information about an author including elements:
+ *   - name: A string with the author's name.
+ *   - cid: An integer identifying the author in biblio module.
+ *   - drupal_uid: (optional) An integer linking to Drupal user ID.
+ *
+ * @ingroup themeable
+ */
 function theme_biblio_author_link($author) {
   $base = variable_get('biblio_base', 'biblio');
   $link_to_profile = variable_get('biblio_author_link_profile', 0);
@@ -652,6 +728,10 @@ function theme_biblio_author_link($author) {
   return $html;
 }
 
+/**
+ * Creates HTML string for a biblio page number or range.
+ *
+
 // Format page information:
 //
 // NOTES: - this function (and refbase in general) assumes following rules for the original formatting of page information in '$origPageInfo':
@@ -667,8 +747,39 @@ function theme_biblio_author_link($author) {
 // TODO:  - should we only use Unicode-aware regex expressions (i.e. always use '$space', '$digit' or '$word' instead of ' ', '\d' or '\w', etc)?
 //        - recognize & process total number of pages
 //        - for '$shortenPageRangeEnd=true', add support for page locators that contain letters (e.g. "A1 - A3" or "4a-4c")
-function theme_biblio_page_number($origPageInfo, $pageRangeDelim = "-", $singlePagePrefix = "", $pageRangePrefix = "", $totalPagesPrefix = "", $singlePageSuffix = "", $pageRangeSuffix = "", $totalPagesSuffix = "", $shortenPageRangeEnd = false)
-{
+ *
+ * // @todo: There are too many parameters here. Changed to an $options array?
+ *
+ * @param $origPageInfo
+ *
+ * @param string $pageRangeDelim
+ *   (optional)
+ * @param string $singlePagePrefix
+ *   (optional)
+ * @param string $pageRangePrefix
+ *   (optional)
+ * @param string $totalPagesPrefix
+ *   (optional)
+ * @param string $singlePageSuffix
+ *   (optional)
+ * @param string $pageRangeSuffix
+ *   (optional)
+ * @param string $totalPagesSuffix
+ *   (optional)
+ * @param bool $shortenPageRangeEnd
+ *   (optional) A logical flag with a default FALSE value.
+ *
+ * @ingroup themeable
+ */
+function theme_biblio_page_number($origPageInfo,
+                                  $pageRangeDelim = "-",
+                                  $singlePagePrefix = "",
+                                  $pageRangePrefix = "",
+                                  $totalPagesPrefix = "",
+                                  $singlePageSuffix = "",
+                                  $pageRangeSuffix = "",
+                                  $totalPagesSuffix = "",
+                                  $shortenPageRangeEnd = FALSE) {
   list($alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower,
        $print, $punct, $space, $upper, $word, $patternModifiers) = _biblio_get_regex_patterns();
 
@@ -729,7 +840,6 @@ function theme_biblio_page_number($origPageInfo, $pageRangeDelim = "-", $singleP
   return $newPageInfo;
 }
 
-
 /**
  * Applies a "style" function to a single node.
  *
@@ -737,7 +847,8 @@ function theme_biblio_page_number($origPageInfo, $pageRangeDelim = "-", $singleP
  * @param $base The base url for biblio (defaults to /biblio)
  * @param $style_name The name of the style to apply
  * @param $inline "inline" mode returns the raw HTML rather than letting drupal render the whole page.
- * @return A string containing the styled (HTML) node
+ *
+ * @ingroup themeable
  */
 function theme_biblio_style($node, $base = 'biblio', $style_name = 'classic', $inline = false) {
   module_load_include('inc', 'biblio', "styles/biblio_style_$style_name");
@@ -752,7 +863,8 @@ function theme_biblio_style($node, $base = 'biblio', $style_name = 'classic', $i
  * @param $base
  * @param $style
  * @param $inline
- * @return unknown_type
+ *
+ * @ingroup themeable
  */
 function theme_biblio_entry($node, $base = 'biblio', $style = 'classic', $inline = false) {
   $output  = "\n".'<div class="biblio-entry">' . "\n" ;
@@ -799,18 +911,24 @@ function theme_biblio_entry($node, $base = 'biblio', $style = 'classic', $inline
 }
 
 /**
+ *
+ *
  * @param $form
- * @return unknown_type
+ *
+ * @see biblio_filters()
+ *
+ * @ingroup themeable
  */
 function theme_biblio_filters($form) {
+  $output = '';
   if (sizeof($form['current'])) {
     $output .= '<ul>';
     foreach (element_children($form['current']) as $key) {
-      $output .= '<li>'. drupal_render($form['current'][$key]) .'</li>';
+      $output .= '<li>' . drupal_render($form['current'][$key]) . '</li>';
     }
     $output .= '</ul>';
   }
-  $output .= '<dl class="multiselect">'. (sizeof($form['current']) ? '<dt><em>'. t('and') .'</em> '. t('where') .'</dt>' : '') .'<dd class="a">';
+  $output .= '<dl class="multiselect">' . (sizeof($form['current']) ? '<dt><em>' . t('and') . '</em> ' . t('where') . '</dt>' : '') . '<dd class="a">';
   foreach (element_children($form['filter']) as $key) {
     $output .= drupal_render($form['filter'][$key]);
   }
@@ -821,14 +939,17 @@ function theme_biblio_filters($form) {
   }
   $output .= '</dd>';
   $output .= '</dl>';
-  $output .= '<div class="container-inline" id="node-buttons">'. drupal_render($form['buttons']) .'</div>';
+  $output .= '<div class="container-inline" id="node-buttons">' . drupal_render($form['buttons']) . '</div>';
   $output .= '<br class="clear" />';
   return $output;
 }
 
 /**
  * @param $form
- * @return unknown_type
+ *
+ * @see biblio_admin_types_edit_form()
+ *
+ * @ingroup themeable
  */
 function theme_biblio_form_filter($form) {
   $output .= '<div id="biblio-admin-filter">';
@@ -839,16 +960,21 @@ function theme_biblio_form_filter($form) {
 }
 
 /**
+ * Creates the HTML for the biblio_admin_types_edit_form().
+ *
  * @param $form
- * @return unknown_type
+ *
+ *
+ * @see biblio_admin_types_edit_form()
+ *
+ * @ingroup themeable
  */
 function theme_biblio_admin_types_edit_form($form) {
-  drupal_add_tabledrag('field-table', 'order', 'sibling', 'weight',NULL,NULL,false);
+  drupal_add_tabledrag('field-table', 'order', 'sibling', 'weight', NULL, NULL, FALSE);
 
   $tid = (!empty ($form['#parameters'][2])) ? $form['#parameters'][2] : FALSE;
-  //  drupal_set_title($form['type_name'] ? $form['type_name']['#value'] : t('Common'));
 
-  // build the table with all the fields if no $tid is given, or only the common
+  // Build the table with all the fields if no $tid is given, or only the common
   // and customized fields if $tid is given
   $conf_table = array();
   foreach (element_children($form['configured_flds']) as $fld) {
@@ -861,7 +987,8 @@ function theme_biblio_admin_types_edit_form($form) {
       $form['configured_flds'][$fld]['hint']['#size'] = 15;
       $conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['hint']));
       $conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['auth_type']));
-    } else {
+    }
+    else {
       $form['configured_flds'][$fld]['hint']['#size'] = ($tid ? 38: 36);
       $conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['hint']), 'colspan' => 2);
     }
@@ -882,21 +1009,29 @@ function theme_biblio_admin_types_edit_form($form) {
     $header = array(t('Field Name'), t('Default Title'), t('Hint'), '', t('Common'), t('Required'), t('Autocomplete'), t('Weight'));
   }
   $output = '<p>';
-  $output .= '<h2>'. drupal_render($form['top_message']) .'</h2>';
+  $output .= '<h2>' . drupal_render($form['top_message']) . '</h2>';
   $output .= drupal_render($form['help']);
   $output .= drupal_render($form['type_name']);
   $output .= drupal_render($form['options']);
   $output .= theme('table', $header, $conf_table, array('id' => 'field-table'));
-  $output .= '<p><center>'. drupal_render($form['submit']) .'</center></p>';
+  $output .= '<p><center>' . drupal_render($form['submit']) . '</center></p>';
   $output .= drupal_render($form);
   return $output;
 }
 
+/**
+ * Creates HTML-formatted string for biblio download links.
+ *
+ * @param object $node
+ *   (optional)
+ *
+ * @ingroup themeable
+ */
 function theme_biblio_download_links($node = NULL) {
   $files = '';
   if (!empty ($node->files) && count($node->files) > 0 && user_access('view uploaded files')) {
     $files .= '<span class="biblio_file_links">';
-    $files .= '&nbsp;'. t('Download') .':&nbsp;';
+    $files .= '&nbsp;' . t('Download') . ':&nbsp;';
     $file_count = 0;
     foreach ($node->files as $file) {
       if ($file->list) {
@@ -908,13 +1043,14 @@ function theme_biblio_download_links($node = NULL) {
         }
         $text = $file->description ? $file->description : $file->filename;
         if ($file_count) $files .= '; ';
-        $files .= l($text, $href) .'&nbsp;('. format_size($file->filesize).')';
+        $files .= l($text, $href) . '&nbsp;(' . format_size($file->filesize) . ')';
         $file_count++;
       }
     }
     $files .= '</span>';
   }
-  if (module_exists('filefield')) { // now lets get any CCK FileField files...
+  // Now add any CCK FileField files ...
+  if (module_exists('filefield')) {
     $fields = filefield_get_field_list('biblio');
     foreach ($fields as $field_name => $field) {
       if (filefield_view_access($field_name, $node)) {
@@ -929,19 +1065,24 @@ function theme_biblio_download_links($node = NULL) {
       }
     }
   }
-
   return $files;
 }
 
 /**
- * Creates a group of links for the various export functions
- * @param $nid the node id to export (if omitted, all nodes in the current view will be exported
- * @return an un-ordered list of class "biblio-export-buttons"
+ * Creates a group of links for the various export functions.
+ *
+ * @param $nid
+ *   the node id to export (if omitted, all nodes in the current view will be exported
+ *
+ * @ingroup themeable
  */
 function theme_biblio_export_links($node = NULL) {
-  if (!isset($node->nid)) return;
-  $output = '';
   global $pager_total_items;
+  $output = '';
+  if (!isset($node->nid))
+    // @todo: Should not this return an empty string rather than NULL?
+    return;
+  }
   $links = array();
   $base = variable_get('biblio_base', 'biblio');
 
@@ -951,18 +1092,23 @@ function theme_biblio_export_links($node = NULL) {
     if ($show_link['google'] && !empty($node)) {
       $lookup_links['biblio_google_scholar'] = theme('google_scholar_link', $node);
     }
-
     $export_links = module_invoke_all('biblio_export_link', $node->nid);
     $links = array_merge($lookup_links, $export_links);
   }
   if (empty($node) && !empty($links)) {
-    $output = t('Export @count results', array('@count' => $pager_total_items[0])).': ';
+    $output = t('Export @count results', array('@count' => $pager_total_items[0])) . ': ';
   }
   return $output . theme('links', $links, array('class' => "biblio-export-buttons"));
-
 }
 
-
+/**
+ *
+ *
+ * @param object $node
+ *
+ *
+ * @ingroup themeable
+ */
 function theme_google_scholar_link($node) {
   $query = array();
 
@@ -994,13 +1140,20 @@ function theme_google_scholar_link($node) {
 }
 
 /**
+ *
+ *
  * @param $form
- * @return unknown_type
+ *
+ * @ingroup themeable
  */
 function theme_biblio_contributors($form) {
   $rows = array();
-  if ($form['#hideRole']) $headers = array('', t('Name'), t('Weight'));
-  else $headers = array('', t('Name'), t('Role'), t('Weight'));
+  if ($form['#hideRole']) {
+    $headers = array('', t('Name'), t('Weight'));
+  }
+  else {
+    $headers = array('', t('Name'), t('Role'), t('Weight'));
+  }
   drupal_add_tabledrag($form['#id'], 'order', 'sibling', 'rank');
 
   foreach (element_children($form) as $key) {
@@ -1010,6 +1163,7 @@ function theme_biblio_contributors($form) {
     $form[$key]['rank']['#attributes']['class'] = 'rank';
 
     // Build the table row.
+    // @todo: Explain why first element of row is set to empty string.
     $row = array('');
     $row[] = array('data' => drupal_render($form[$key]['name']),
                    'class' => 'biblio-contributor');
@@ -1026,16 +1180,24 @@ function theme_biblio_contributors($form) {
 }
 
 /**
+ *
+ *
  * This function creates a string of letters (A - Z), which
  * depending on the sorting are either linked to author or title
  * filters i.e. clicking on the A when in the listing is sorted by
  * authors will bring up a list of all the entries where the first
  * character of the primary authors last name is "A"
  *
- * @param $type either "author or title"
- * @return a chunk of HTML code as described above
+ * @param string $type
+ *   (optional) Either 'author' or 'title' with a default of 'author'.
+ * @param $current
+ *   (optional)
+ * @param $path
+ *   (optional)
+ *
+ * @ingroup themeable
  */
-function theme_biblio_alpha_line($type = 'author',$current = NULL, $path = NULL) {
+function theme_biblio_alpha_line($type = 'author', $current = NULL, $path = NULL) {
   $options = array();
   $base = variable_get('biblio_base', 'biblio');
   $all = '';
@@ -1043,38 +1205,45 @@ function theme_biblio_alpha_line($type = 'author',$current = NULL, $path = NULL)
     case 'authors':
     case 'keywords':
       $path =  (ord(substr($_GET['q'],-1)) > 97) ? $_GET['q'] . "/" : substr($_GET['q'], 0, -1);
-      $all = '['.l(t('Show ALL'), substr($_GET['q'], 0, -2)).']' ;
+      $all = '[' . l(t('Show ALL'), substr($_GET['q'], 0, -2)) . ']';
       break;
+
     case 'keyword':
       $options['query'] = array('sort' => 'keyword');
       $path = "$base/keyword/";
       $all_query['query'] = array('sort' => 'keyword', 'order' => $_GET['order']);
-      $all = '['.l(t('Show ALL'), $base,$all_query).']' ;
+      $all = '[' . l(t('Show ALL'), $base, $all_query) . ']';
       break;
+
     case 'author':
       $options['query'] = array('sort' => 'author');
       $path = "$base/ag/";
       $all_query['query'] = array('sort' => 'author', 'order' => $_GET['order']);
-      $all = '['.l(t('Show ALL'), $base,$all_query).']' ;
+      $all = '[' . l(t('Show ALL'), $base, $all_query) . ']';
       break;
+
     case 'title':
       $options['query'] = array('sort' => 'title');
       $path = "$base/tg/";
       $all_query['query'] = array('sort' => 'title', 'order' => $_GET['order']);
-      $all = '['.l(t('Show ALL'), $base,$all_query).']' ;
+      $all = '['. l(t('Show ALL'), $base, $all_query) . ']';
       break;
+
     default:
-      if (!isset ($_GET['sort']) || $_GET['sort'] == 'year' || $_GET['sort'] == 'type')
-      return;
+      if (!isset ($_GET['sort']) || $_GET['sort'] == 'year' || $_GET['sort'] == 'type') {
+        return;
+      }
       $inline = $inline ? "/inline" : "";
       if (isset ($_GET['sort'])) {
         $options['query']['sort'] = $_GET['sort'];
-        if ($_GET['sort'] == 'author')
-        $path = "$base/ag/";
-        if ($_GET['sort'] == 'title')
-        $path = "$base/tg/";
+        if ($_GET['sort'] == 'author') {
+          $path = "$base/ag/";
+        }
+        if ($_GET['sort'] == 'title') {
+          $path = "$base/tg/";
+        }
       }
-
+      break;
   }
   if (isset ($_GET['order'])) {
     $options['query']['order'] = $_GET['order'];
@@ -1082,13 +1251,15 @@ function theme_biblio_alpha_line($type = 'author',$current = NULL, $path = NULL)
   $output = '<div class="biblio-alpha-line">';
   for ($i = 65; $i <= 90; $i++) {
     if ($i == ord(strtoupper($current))){
-      $output .= '<b>['.chr($i).']</b>&nbsp;';
+      $output .= '<b>['. chr($i) . ']</b>&nbsp;';
     }
     else{
-      $output .= l(chr($i), $path. chr($i), $options) .'&nbsp;';
+      $output .= l(chr($i), $path . chr($i), $options) . '&nbsp;';
     }
   }
-  if($current) $output .= '&nbsp;&nbsp;'.$all;
+  if ($current) {
+    $output .= '&nbsp;&nbsp;' . $all;
+  }
   $output .= '</div>';
   return $output;
 }
@@ -1098,6 +1269,8 @@ function theme_biblio_alpha_line($type = 'author',$current = NULL, $path = NULL)
  *
  * @param $form
  * @return rendered form
+ *
+ * @ingroup themeable
  */
 function theme_biblio_admin_author_edit_form($form){
   $rows = array();
@@ -1116,11 +1289,14 @@ function theme_biblio_admin_author_edit_form($form){
   $output .= drupal_render($form['merge']);
   $output .= drupal_render($form['link']);
   $output .= drupal_render($form);
-
   return $output;
-
 }
 
+/**
+ *
+ *
+ * @ingroup themeable
+ */
 function theme_biblio_admin_orphans_form($form) {
   // If there are any orphans, then $form['name'] contains a list of the author names
   $has_items = isset($form['name']) && is_array($form['name']);
@@ -1146,11 +1322,16 @@ function theme_biblio_admin_orphans_form($form) {
   if ($form['pager']['#value']) {
     $output .= drupal_render($form['pager']);
   }
-
   $output .= drupal_render($form);
-
   return $output;
 }
+
+/**
+ *
+ *
+ *
+ * @ingroup themeable
+ */
 function theme_biblio_admin_keyword_orphans_form($form) {
   // If there are any orphans, then $form['name'] contains a list of the author names
 
@@ -1176,8 +1357,6 @@ function theme_biblio_admin_keyword_orphans_form($form) {
   if ($form['pager']['#value']) {
     $output .= drupal_render($form['pager']);
   }
-
   $output .= drupal_render($form);
-
   return $output;
 }
diff --git a/includes/biblio_xml.inc b/includes/biblio_xml.inc
index 0456ddb..4afc096 100644
--- a/includes/biblio_xml.inc
+++ b/includes/biblio_xml.inc
@@ -1,68 +1,73 @@
 <?php
 /**
- *
- *   Copyright (C) 2006-2008  Ron Jerome
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License along
- *   with this program; if not, write to the Free Software Foundation, Inc.,
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- ****************************************************************************/
-
+ * @file
+ * XML related functions for Drupal biblio module.
+ */
 
 /**
+ * Generates XML output containing all biblio content and their revisions.
+ *
  * @param $result
+ *   // @todo: This parameter is never used.  Should it be removed?
+ *
  * @return unknown_type
+ *
  */
-function biblio_xml_export($result){
+function biblio_xml_export($result) {
   set_time_limit(300);
-  $nid=0;
+  $nid = 0;
   $dom = new DOMDocument('1.0', 'UTF-8');
   $biblio_collection = $dom->appendChild(new DOMElement('biblio_collection'));
   $biblio_collection->setAttribute("Schema", "6010");
   $comment = $biblio_collection->appendChild(new DOMComment('Generated by the Biblio module from Drupal (http://drupal.org/project/biblio)'));
-  $db_result = db_query("SELECT nr.nid, nr.vid  FROM {node_revisions} nr join node n on nr.nid=n.nid where n.type='biblio' order by nr.nid, nr.vid");
-  while($n=db_fetch_object($db_result)){
-    $node = node_load($n->nid,$n->vid);
-    if($n->nid == $nid){
+  $db_result = db_query("SELECT nr.nid, nr.vid FROM {node_revisions} nr join node n on nr.nid=n.nid where n.type='biblio' order by nr.nid, nr.vid");
+  while ($n = db_fetch_object($db_result)){
+    $node = node_load($n->nid, $n->vid);
+    if ($n->nid == $nid) {
       $revision = $domnode->appendChild(new DOMElement('revision'));
-      $node = (array)$node;
-      AtoX($node, $dom, $revision);
-    }else{
+      $node = (array) $node;
+      _biblio_AtoX($node, $dom, $revision);
+    }
+    else {
       $domnode = $biblio_collection->appendChild(new DOMElement('node'));
-      $node = (array)$node;
-      AtoX($node, $dom, $domnode);
+      $node = (array) $node;
+      _biblio_AtoX($node, $dom, $domnode);
     }
     $nid = $n->nid;
-
   }
   return $dom->saveXML();
 }
 
-function AtoX($array, $DOM=null, $root=null){
-  foreach($array as $key => $value){
-    if ($key == 'biblio_contributors') $name = 'contributor';
-    if (is_numeric($key)) $key = 'c_'.$key;
-    if(is_array($value ) && count($value)){
+/**
+ * Helper function to ...
+ *
+ * @param array $array
+ *
+ * @param $DOM
+ *
+ * @param $root
+ *
+ *
+ * @return 
+ *
+ */
+function _biblio_AtoX($array, $DOM = NULL, $root = NULL) {
+  foreach ($array as $key => $value) {
+    if ($key == 'biblio_contributors') {
+      $name = 'contributor';
+    }
+    if (is_numeric($key)) {
+      $key = 'c_' . $key;
+    }
+    if (is_array($value ) && count($value)) {
       $subroot = $root->appendChild($DOM->createElement($key));
-      AtoX($value, $DOM, $subroot);
+      _biblio_AtoX($value, $DOM, $subroot);
     }
     else {
-      if(!empty($value)){
+      if(!empty($value)) {
         $root->appendChild($DOM->createElement($key, htmlspecialchars($value, ENT_QUOTES)));
       }
     }
   }
-   
   return $DOM;
 }
diff --git a/includes/content.biblio.inc b/includes/content.biblio.inc
index 247064b..9586085 100644
--- a/includes/content.biblio.inc
+++ b/includes/content.biblio.inc
@@ -1,4 +1,18 @@
 <?php
+/**
+ * @file
+ * Functions regarding content extra fields for Drupal biblio module.
+ */
+
+/**
+ * Creates additional form fields for the biblio content type.
+ *
+ * @param string $type_name
+ *
+ *
+ * @return array
+ *
+ */
 function _biblio_content_extra_fields($type_name) {
   $extras = array();
   if ($type_name == 'biblio') {
@@ -19,22 +33,22 @@ function _biblio_content_extra_fields($type_name) {
 
     foreach ($fields as $key => $fld) {
       $label = check_plain($fld['title']);
-      if ($fld['type'] == 'textarea' ||  $fld['type'] == 'contrib_widget') {
-        $key = $key .'_field';
-        $label = $label . ' (' . t('Fieldset') .')';
+      if ($fld['type'] == 'textarea' || $fld['type'] == 'contrib_widget') {
+        $key = $key . '_field';
+        $label = $label . ' (' . t('Fieldset') . ')';
       }
       $extras[$key] = array(
         'label'       => $label,
         'description' => t('Biblio module form.'),
-        'weight'      => $fld['weight'] / 10
+        'weight'      => $fld['weight'] / 10,
       );
     }
     $extras['other_fields'] = array(
-      'label'       => t('Other Biblio Fields') . ' (' . t('Fieldset') .')',
+      'label'       => t('Other Biblio Fields') . ' (' . t('Fieldset') . ')',
       'description' => t('Biblio module form.'),
-      'weight'      => 0
-      );
+      'weight'      => 0,
+    );
 
   }
   return $extras;
-}
\ No newline at end of file
+}
diff --git a/styles/biblio_style_classic.inc b/styles/biblio_style_classic.inc
index f11baab..db8c2f3 100644
--- a/styles/biblio_style_classic.inc
+++ b/styles/biblio_style_classic.inc
@@ -58,6 +58,7 @@ function biblio_style_classic_author_options() {
 function biblio_style_classic($node, $base = 'biblio', $inline = FALSE) {
   $output = '';
   $author_options = biblio_style_classic_author_options();
+  $authors = '';
   if (isset($node->biblio_contributors[1])) {
     $authors = theme('biblio_format_authors', $node->biblio_contributors[1], $author_options, $inline);
   }
diff --git a/tests/biblio.test b/tests/biblio.test
index 1352fde..59a6199 100644
--- a/tests/biblio.test
+++ b/tests/biblio.test
@@ -4,9 +4,12 @@
  * Base class for all biblio tests
  */
 class BiblioWebTestCase extends DrupalWebTestCase {
-  protected $kids = array();  //keep a list of all keyword id's created
-  protected $cids = array();  //keep a list of all contributor id's created
-  protected $nids = array();  //keep a list of all node id's created
+  // Keep a list of all keyword IDs created.
+  protected $kids = array();
+  // Keep a list of all contributor IDs created.    
+  protected $cids = array();
+  // Keep a list of all node IDs created.  
+  protected $nids = array();
   protected $admin_user;
 
   function tearDown() {
@@ -26,7 +29,6 @@ class BiblioWebTestCase extends DrupalWebTestCase {
     $this->cids = array();
   }
 
-
   function createNode($type = 100, $fields = null) {
     if(!$fields) {
     $schema = drupal_get_schema('biblio');
@@ -69,8 +71,8 @@ class BiblioWebTestCase extends DrupalWebTestCase {
     $this->nids[] = $node->nid;
 
     return $node;
-
   }
+  
   function assertBiblioFields($node1, $node2, $fields = array()) {
     $count = 0;
     $cat = 0;
@@ -95,4 +97,4 @@ class BiblioWebTestCase extends DrupalWebTestCase {
     }
     $this->assertEqual($count, 0, "There were $count differences between the two nodes");
   }
-}
\ No newline at end of file
+}
diff --git a/tests/contributor.test b/tests/contributor.test
index 8c461cc..20dcde8 100644
--- a/tests/contributor.test
+++ b/tests/contributor.test
@@ -2,15 +2,13 @@
 /*
  * @file
  * Tests for contributor handling in the Biblio module
- *
  */
 
 class BiblioContributorWebTestCase extends BiblioWebTestCase {
+
   function setUp() {
     require_once(drupal_get_path('module', 'biblio') .'/biblio.contributors.inc');
   }
-
-
 }
 
 class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
@@ -24,7 +22,6 @@ class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
   }
 
   function testGrabSurname() {
-
     $surname = 'van der Plus';
     list ($surname, $prefix) = _grabSurname($surname);
     $this->assertIdentical($surname, 'Plus' );
@@ -34,8 +31,8 @@ class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
     $this->assertIdentical($surname, 'Van den Bussche' );
     $this->assertIdentical($prefix, FALSE );
   }
-  function testGrabFirstnameInitials() {
 
+  function testGrabFirstnameInitials() {
     $string = "Ron";
     list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
     $this->assertIdentical($firstname, 'Ron' );
@@ -61,22 +58,18 @@ class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
     list($firstname,$initials,$prefix) = _grabFirstnameInitials($string);
     $this->assertIdentical($firstname, '' );
     $this->assertIdentical($initials, 'R J' );
-
   }
 
   function testBiblioParseAuthor() {
-
     $author['name'] = 'Bush, Jr. III, George W';
     $author = biblio_parse_author($author);
     $this->assertIdentical($author['firstname'], 'George', 'Test biblio_parse_author($author), firstname' );
     $this->assertIdentical($author['lastname'], 'Bush', 'Test biblio_parse_author($author), lastname');
     $this->assertIdentical($author['initials'], 'W', 'Test biblio_parse_author($author), initials' );
     $this->assertIdentical($author['suffix'], 'Jr. III', 'Test biblio_parse_author($author), suffix' );
-
   }
 
   function testBiblioUpdateContributors() {
-
     $node = $this->createNode();
     $nid = $node->nid;
     $vid1 = $node->vid;
@@ -100,7 +93,6 @@ class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
     biblio_delete_contributors($node);
     $node = node_load($nid, NULL, TRUE);
     $this->assertFalse(count($node->biblio_contributors),'Test biblio_delete_contributors($node), should be zero authors on reload');
-
   }
 
   function testBiblioDeleteOrphanAuthors() {
@@ -124,7 +116,5 @@ class BiblioContributorUnitTest extends BiblioContributorWebTestCase {
     }
     $restored_count = biblio_count_orphan_authors();
     $this->assertEqual($orphan_count, $restored_count, "Restored $restored_count of $orphan_count original orphans");
-
   }
-
 }
diff --git a/tests/import.export.test b/tests/import.export.test
index 00a5024..9af6409 100644
--- a/tests/import.export.test
+++ b/tests/import.export.test
@@ -1,12 +1,17 @@
 <?php
+/**
+ * @file
+ * Tests for import/export functionality for Drupal biblio module.
+ */
+
 class BiblioImportExportWebTestCase extends BiblioWebTestCase {
+
   function setUp() {
     module_load_include('inc', 'biblio', 'biblio.import.export');
     module_load_include('module', 'biblio_xml', 'biblio_xml');
     module_load_include('inc', 'biblio_xml', 'endnote8_export');
     module_load_include('module', 'biblio_tagged', 'biblio_tagged');
     module_load_include('module', 'biblio_bibtex', 'biblio_bibtex');
-
   }
 }
 
@@ -19,6 +24,7 @@ class BiblioImportExportUnitTest extends BiblioImportExportWebTestCase {
       'group' => 'Biblio',
     );
   }
+  
   function getTaggedString() {
     return  "%0 Book\r\n%B biblio_secondary_title\r\n%D 2009\r\n%T Biblio Title\r\n%A Ron J. Jeromezzzzzz\r\n%A John Smithzzzzzz\r\n%A George W. Bushzzzzzz\r\n%K biblio_keywords\r\n%X biblio_abst_e\r\n%B biblio_secondary_title\r\n%S biblio_tertiary_title\r\n%7 biblio_edition\r\n%I biblio_publisher\r\n%C biblio_place_published\r\n%V biblio_volume\r\n%P biblio_pages\r\n%8 biblio_date\r\n%@ biblio_isbn\r\n%G biblio_lang\r\n%U biblio_url\r\n%N biblio_issue\r\n%9 biblio_type_of_work\r\n%M biblio_accession_number\r\n%L biblio_call_number\r\n%1 biblio_custom1\r\n%2 biblio_custom2\r\n%3 biblio_custom3\r\n%4 biblio_custom4\r\n%# biblio_custom5\r\n%$ biblio_custom6\r\n%] biblio_custom7\r\n%< biblio_research_notes\r\n%6 biblio_number_of_volumes\r\n%R biblio_doi\r\n%F biblio_label\r\n\r\n";
   }
@@ -45,7 +51,6 @@ class BiblioImportExportUnitTest extends BiblioImportExportWebTestCase {
     $xml .= _endnote8_XML_export($node);
     $xml .= _endnote8_XML_export('', 'end');
     $this->assertEqual($xml, $this->getXMLString(), 'Export a node in EndNote XML format');
-
   }
 
   function testBiblioXMLFileImport() {
@@ -128,4 +133,4 @@ class BiblioImportExportUnitTest extends BiblioImportExportWebTestCase {
 //    }
 //  }
 
-}
\ No newline at end of file
+}
diff --git a/tests/keyword.test b/tests/keyword.test
index 0e34aba..248f905 100644
--- a/tests/keyword.test
+++ b/tests/keyword.test
@@ -1,8 +1,7 @@
 <?php
-
 /**
  * @file
- * Tests for keyword functions.
+ * Tests for keyword functions in Drupal biblio module.
  */
 
 /**
@@ -24,7 +23,6 @@ class BiblioKeywordWebTestCase extends BiblioWebTestCase {
     $this->kids[] = $keyword['kid'];
     return $keyword;
   }
-
 }
 
 /**
@@ -39,20 +37,24 @@ class BiblioKeywordUnitTest extends BiblioKeywordWebTestCase {
       'group' => 'Biblio',
     );
   }
+  
   function testBiblioSaveKeyword() {
     $keyword = $this->createKeyword();
     $this->assertTrue($keyword['kid'], t('Created and saved a single keyword'));
   }
+  
   function testBiblioDeleteKeyword() {
     $keyword = $this->createKeyword();
     $num_deleted = biblio_delete_keyword($keyword['kid']);
     $this->assertEqual($num_deleted, 1, t('Deleted a single keyword'));
   }
+  
   function testBiblioGetKeywordById() {
     $keyword = $this->createKeyword();
     $word = biblio_get_keyword_by_id($keyword['kid']);
     $this->assertEqual($keyword, $word, 'Get keyword by ID');
   }
+  
   function testBiblioGetKeywordByName() {
     $keyword = $this->createKeyword();
 
@@ -81,7 +83,6 @@ class BiblioKeywordUnitTest extends BiblioKeywordWebTestCase {
     $this->assertFalse($word, t('Tried to load a keyword using a substring of the word'));
   }
 
-
   function testBiblioUpdateKeywords() {
     $term1 = $this->createKeyword();
     $node = $this->createNode();
@@ -142,7 +143,4 @@ class BiblioKeywordUnitTest extends BiblioKeywordWebTestCase {
 
     $this->assertEqual($words, $exploded, "Exploded a keyword string which contains and escaped separator");
   }
-
 }
-
-
diff --git a/views/biblio.views.inc b/views/biblio.views.inc
index d6619f5..3b6284c 100644
--- a/views/biblio.views.inc
+++ b/views/biblio.views.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Functions for views integration for Drupal biblio module.
+ */
+
 function biblio_views_plugins() {
 // Not ready for prime time!!!
 //  return array(
@@ -40,9 +45,9 @@ function biblio_views_handlers() {
       'path' => drupal_get_path('module', 'biblio') . '/views',
     ),
     'handlers' => array(
-/*
- * Fields
- */
+      //
+      // Fields
+      //
       'biblio_handler_field' => array(
         'parent' => 'views_handler_field',
       ),
@@ -64,9 +69,10 @@ function biblio_views_handlers() {
       'biblio_handler_field_export_link' => array(
         'parent' => 'views_handler_field',
       ),
-/*
- * Filters
- */
+      
+      //
+      // Filters
+      //
       'biblio_handler_filter_contributor' => array(
         'parent' => 'views_handler_filter_many_to_one',
       ),
@@ -82,26 +88,26 @@ function biblio_views_handlers() {
       'biblio_handler_filter_biblio_keyword_kid' => array(
         'parent' => 'views_handler_filter_many_to_one',
       ),
-/*
- *  Arguments
- */
+      
+      //
+      // Arguments
+      //
       'biblio_handler_argument_many_to_one' => array(
         'parent' => 'views_handler_argument_many_to_one',
       ),
-/*
- *  Sort
- */
+
+      //
+      // Sort
+      //
       'biblio_handler_sort_contributor_lastname' => array(
         'parent' => 'views_handler_sort',
       ),
-
-
-      )
+    )
   );
 }
 
 /**
- * Implementation of hook_views_data().
+ * Implements hook_views_data().
  *
  * Exposes all fields to the views system.
  */
@@ -303,9 +309,7 @@ function biblio_views_data() {
 
   $viewsdata['biblio_contributor_data'] = $data;
 
-
-
-/***************** Describe the keyword table *************/
+  /***************** Describe the keyword table *************/
 
   $data = array();
   $data['table']['group'] = t('Biblio');
@@ -348,7 +352,7 @@ function biblio_views_data() {
 
   $viewsdata['biblio_keyword'] = $data;
 
-/***************** Describe the keyword_data table ***********/
+  /***************** Describe the keyword_data table ***********/
 
   $data = array();
   $data['table']['group'] = t('Biblio');
@@ -389,15 +393,20 @@ function biblio_views_data() {
     'skip base' => array('node', 'node_revision'),
   );
 
-
   $viewsdata['biblio_keyword_data'] = $data;
 
   return $viewsdata;
 }
 
+/**
+ * Preprocess function for views ....
+ *
+ * @param $vars
+ *
+ */
 function template_preprocess_views_view_unformatted__biblio_year(&$vars) {
-  $view     = $vars['view'];
-  $rows     = $vars['rows'];
+  $view = $vars['view'];
+  $rows = $vars['rows'];
 
   $vars['classes'] = array();
   // Set up striping values.
diff --git a/views/biblio_handler_citation.inc b/views/biblio_handler_citation.inc
index 3d8f5df..af93ddd 100644
--- a/views/biblio_handler_citation.inc
+++ b/views/biblio_handler_citation.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Views citation handler for Drupal biblio module.
+ */
+
 class biblio_handler_citation extends views_handler_field {
   var $author_options;
   var $biblio_base;
@@ -11,6 +16,7 @@ class biblio_handler_citation extends views_handler_field {
   function query() {
     $this->add_additional_fields();
   }
+
   function option_definition() {
     $options = parent::option_definition();
     $options['style_name'] = array('default' => biblio_get_style());
@@ -19,6 +25,7 @@ class biblio_handler_citation extends views_handler_field {
     $options['open_url_link'] = array('default' => 1);
     return $options;
   }
+
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
     $form['style_name'] = array(
@@ -96,5 +103,4 @@ class biblio_handler_citation extends views_handler_field {
 
     return $output;
   }
-
-}
\ No newline at end of file
+}
diff --git a/views/biblio_handler_field.inc b/views/biblio_handler_field.inc
index 57c2535..3eba55f 100644
--- a/views/biblio_handler_field.inc
+++ b/views/biblio_handler_field.inc
@@ -1,4 +1,8 @@
 <?php
+/**
+ * @file
+ * Views field handler for Drupal biblio module.
+ */
 
 class biblio_handler_field extends views_handler_field {
   function init(&$view, $options) {
@@ -27,6 +31,7 @@ class biblio_handler_field extends views_handler_field {
 
     return $options;
   }
+  
   function options_form(&$form, &$form_state) {
     $form['biblio_label'] = array(
       '#type' => 'checkbox',
@@ -43,6 +48,7 @@ class biblio_handler_field extends views_handler_field {
       ),
     );
   }
+  
   function set_label(&$values) {
     if (!$this->options['biblio_label']) return;
     $tid = $values->biblio_tid;
@@ -62,4 +68,4 @@ class biblio_handler_field extends views_handler_field {
    $this->set_label($values);
    return parent::render($values);
   }
-}
\ No newline at end of file
+}
diff --git a/views/biblio_handler_field_biblio_keyword_data_word.inc b/views/biblio_handler_field_biblio_keyword_data_word.inc
index 35e09be..cf7040f 100644
--- a/views/biblio_handler_field_biblio_keyword_data_word.inc
+++ b/views/biblio_handler_field_biblio_keyword_data_word.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Views biblio keyword data word handler for Drupal biblio module.
+ */
+ 
 class biblio_handler_field_biblio_keyword_data_word extends views_handler_field {
   /**
    * Constructor to provide additional field to add.
diff --git a/views/biblio_handler_field_biblio_keyword_kid.inc b/views/biblio_handler_field_biblio_keyword_kid.inc
index f059fa7..a318786 100644
--- a/views/biblio_handler_field_biblio_keyword_kid.inc
+++ b/views/biblio_handler_field_biblio_keyword_kid.inc
@@ -1,5 +1,9 @@
 <?php
-
+/**
+ * @file
+ * Views biblio keyword kid handler for Drupal biblio module.
+ */
+ 
 class biblio_handler_field_biblio_keyword_kid extends views_handler_field_prerender_list {
   function init(&$view, $options) {
     parent::init($view, $options);
@@ -11,7 +15,6 @@ class biblio_handler_field_biblio_keyword_kid extends views_handler_field_preren
     }
   }
 
-
   function pre_render($values) {
     $this->field_alias = $this->aliases['vid'];
     $vids = array();
diff --git a/views/biblio_handler_field_biblio_type.inc b/views/biblio_handler_field_biblio_type.inc
index 25344ea..47a20d3 100644
--- a/views/biblio_handler_field_biblio_type.inc
+++ b/views/biblio_handler_field_biblio_type.inc
@@ -1,5 +1,9 @@
 <?php
-
+/**
+ * @file
+ * Views biblio type handler for Drupal biblio module.
+ */
+ 
 class biblio_handler_field_biblio_type extends views_handler_field {
   function init(&$view, $options) {
     parent::init($view, $options);
@@ -11,7 +15,6 @@ class biblio_handler_field_biblio_type extends views_handler_field {
     }
   }
 
-
   function pre_render($values) {
     $this->field_alias = $this->aliases['vid'];
     $vids = array();
@@ -20,7 +23,6 @@ class biblio_handler_field_biblio_type extends views_handler_field {
         $vids[] = $result->{$this->aliases['vid']};
       }
     }
-    //print_r($values);
     if ($vids) {
 
       //$result = db_query("SELECT bt.name AS node_vid, bkd.* FROM {biblio_keyword_data} bkd INNER JOIN {biblio_keyword} bk ON bkd.kid = bk.kid WHERE bk.vid IN (" . implode(', ', $vids) . ") ORDER BY  bkd.word");
diff --git a/views/biblio_handler_field_contributor.inc b/views/biblio_handler_field_contributor.inc
index 635ec06..885a78d 100644
--- a/views/biblio_handler_field_contributor.inc
+++ b/views/biblio_handler_field_contributor.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Views biblio contributor handler for Drupal biblio module.
+ */
+
 class biblio_handler_field_contributor extends biblio_handler_field {
   function construct() {
     module_load_include('inc', 'biblio', 'includes/biblio_theme');
@@ -13,6 +18,7 @@ class biblio_handler_field_contributor extends biblio_handler_field {
     $options['style_name'] = array('default' => biblio_get_style());
     return $options;
   }
+  
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
     module_load_include('inc', 'biblio', 'includes/biblio.admin');
@@ -70,4 +76,4 @@ class biblio_handler_field_contributor extends biblio_handler_field {
     if (!isset($this->items[$vid])) return NULL;
     return biblio_format_authors($this->items[$vid]);
   }
-}
\ No newline at end of file
+}
diff --git a/views/biblio_handler_field_export_link.inc b/views/biblio_handler_field_export_link.inc
index b5cd04a..b3b95a6 100644
--- a/views/biblio_handler_field_export_link.inc
+++ b/views/biblio_handler_field_export_link.inc
@@ -1,4 +1,8 @@
 <?php
+/**
+ * @file
+ * Views biblio export link handler for Drupal biblio module.
+ */
 class biblio_handler_field_export_link extends views_handler_field {
   function init(&$view, $options) {
     parent::init($view, $options);
diff --git a/views/biblio_handler_filter_biblio_contributor_auth_type.inc b/views/biblio_handler_filter_biblio_contributor_auth_type.inc
index b6f8a57..323887b 100644
--- a/views/biblio_handler_filter_biblio_contributor_auth_type.inc
+++ b/views/biblio_handler_filter_biblio_contributor_auth_type.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Views biblio contributor auth type handler for Drupal biblio module.
+ */
+ 
 class biblio_handler_filter_biblio_contributor_auth_type extends views_handler_filter_in_operator {
 
   function construct() {
diff --git a/views/biblio_handler_filter_biblio_keyword_kid.inc b/views/biblio_handler_filter_biblio_keyword_kid.inc
index 0c721aa..5e7e3df 100644
--- a/views/biblio_handler_filter_biblio_keyword_kid.inc
+++ b/views/biblio_handler_filter_biblio_keyword_kid.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Views biblio keyword kid handler for Drupal biblio module.
+ */
+
 class biblio_handler_filter_biblio_keyword_kid extends views_handler_filter_many_to_one {
   function has_extra_options() { return TRUE; }
 
@@ -7,7 +12,6 @@ class biblio_handler_filter_biblio_keyword_kid extends views_handler_filter_many
     while ($term = db_fetch_object($result)) {
       $this->value_options[$term->kid] = $term->word;
     }
-
   }
 
   function option_definition() {
@@ -16,12 +20,10 @@ class biblio_handler_filter_biblio_keyword_kid extends views_handler_filter_many
     $options['type'] = array('default' => 'textfield');
     $options['limit'] = array('default' => TRUE);
     $options['kid'] = array('default' => 0);
-
     return $options;
   }
 
   function extra_options_form(&$form, &$form_state) {
-
     if ($this->options['limit']) {
       // We only do this when the form is displayed so this query doesn't run
       // unnecessarily just when the object is constructed.
@@ -34,6 +36,7 @@ class biblio_handler_filter_biblio_keyword_kid extends views_handler_filter_many
       );
     }
   }
+  
   function value_form(&$form, &$form_state) {
     if ($this->options['type'] == 'textfield') {
       $default = '';
@@ -105,11 +108,9 @@ class biblio_handler_filter_biblio_keyword_kid extends views_handler_filter_many
       }
     }
 
-
     if (empty($form_state['exposed'])) {
       // Retain the helper option
       $this->helper->options_form($form, $form_state);
     }
   }
-
 }
diff --git a/views/biblio_handler_filter_biblio_type.inc b/views/biblio_handler_filter_biblio_type.inc
index de877f3..1e59b83 100644
--- a/views/biblio_handler_filter_biblio_type.inc
+++ b/views/biblio_handler_filter_biblio_type.inc
@@ -1,4 +1,9 @@
 <?php
+/**
+ * @file
+ * Views biblio type handler for Drupal biblio module.
+ */
+
 class biblio_handler_filter_biblio_type extends views_handler_filter_in_operator {
 
   function construct() {
diff --git a/views/biblio_handler_filter_contributor.inc b/views/biblio_handler_filter_contributor.inc
index 7fbe5ed..7c98524 100644
--- a/views/biblio_handler_filter_contributor.inc
+++ b/views/biblio_handler_filter_contributor.inc
@@ -1,8 +1,9 @@
 <?php
-
 /**
- * Filter handler for contributors
+ * @file
+ * Views filter handler for biblio contributors for Drupal biblio module.
  */
+
 class biblio_handler_filter_contributor extends views_handler_filter_many_to_one {
   function get_value_options() {
     $result = db_query("SELECT lastname, firstname, initials, cid 
diff --git a/views/biblio_handler_filter_contributor_lastname.inc b/views/biblio_handler_filter_contributor_lastname.inc
index 88d1cc5..f5ebf6c 100644
--- a/views/biblio_handler_filter_contributor_lastname.inc
+++ b/views/biblio_handler_filter_contributor_lastname.inc
@@ -1,7 +1,9 @@
 <?php
 /**
- * Filter handler for contributors
+ * @file
+ * Views filter handler for contributor lastname for Drupal biblio module.
  */
+
 class biblio_handler_filter_contributor_lastname extends views_handler_filter_many_to_one {
   function get_value_options() {
     $result = db_query("SELECT lastname, firstname, initials, cid
diff --git a/views/biblio_handler_filter_contributor_uid.inc b/views/biblio_handler_filter_contributor_uid.inc
index 1192e9c..8b947e5 100644
--- a/views/biblio_handler_filter_contributor_uid.inc
+++ b/views/biblio_handler_filter_contributor_uid.inc
@@ -1,7 +1,9 @@
 <?php
 /**
- * Filter handler for contributors
+ * @file
+ * Views filter handler for contributor uid for Drupal biblio module.
  */
+ 
 class biblio_handler_filter_contributor_uid extends views_handler_filter_many_to_one {
   function get_value_options() {
     $result = db_query("SELECT u.name, lastname, firstname, initials, cid, drupal_uid 
diff --git a/views/biblio_handler_sort_contributor_lastname.inc b/views/biblio_handler_sort_contributor_lastname.inc
index a9c1f97..9f50153 100644
--- a/views/biblio_handler_sort_contributor_lastname.inc
+++ b/views/biblio_handler_sort_contributor_lastname.inc
@@ -1,5 +1,9 @@
 <?php
-
+/**
+ * @file
+ * Views sort handler for contributor lastname for Drupal biblio module.
+ */
+ 
 class biblio_handler_sort_contributor_lastname extends views_handler_sort {
 
   function query() {
@@ -8,4 +12,3 @@ class biblio_handler_sort_contributor_lastname extends views_handler_sort {
   }
 
 }
-
-- 
1.7.6.msysgit.0

