diff --git a/package/project_package.install b/package/project_package.install
index 77b12ed..63d0e88 100644
--- a/package/project_package.install
+++ b/package/project_package.install
@@ -46,6 +46,260 @@ function project_package_schema() {
     ),
     'primary key' => array('package_nid', 'item_nid'),
   );
+  $schema['project_package_remote_item'] = array(
+    'description' => 'Keeps track of what remote items (or libraries) are included in a release of a given package project.',
+    'fields' => array(
+      'id' => array(
+        'description' => 'Primary key: The primary identifier for a remote item.',
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE
+      ),
+      'package_nid' => array(
+        'description' => 'The {node}.nid of the package release node.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'name' => array(
+        'description' => 'A name to describe this remote item.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'url' => array(
+        'description' => 'The URL of a remote item (or library) included as an item in the package.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'primary key' => array('id'),
+    'indexes' => array('project_package_remote_item_package_nid' => array('package_nid')),
+  );
+  $schema['project_package_local_patch'] = array(
+    'description' => 'Keeps track of any patches that are applied in a release of a given package project.',
+    'fields' => array(
+      'package_nid' => array(
+        'description' => 'Primary Key: The {node}.nid of the package release node.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'item_nid' => array(
+        'description' => 'The {node}.nid of a local release node (from the same site) that was patched.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'patch_file_url' => array(
+        'description' => 'The URL where a given patch file applied to a package can be found.',
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'patch_description_url' => array(
+        'description' => 'The (optional) URL where a patch file applied to a package is described.',
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'patch_nid' => array(
+        'description' => 'The (optional) {node}.nid of a node on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+      'patch_comment_id' => array(
+        'description' => 'The (optional) {comment}.cid of a comment on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('package_nid', array('patch_file_url', 255)),
+  );
+  $schema['project_package_remote_patch'] = array(
+    'description' => 'Keeps track of any patches that are applied in a release of a given package project.',
+    'fields' => array(
+      'package_nid' => array(
+        'description' => 'Primary Key: The {node}.nid of the package release node.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'remote_id' => array(
+        'description' => 'The {project_package_remote_item}.id of a remote item (or library) that was patched.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'patch_file_url' => array(
+        'description' => 'The URL where a given patch file applied to a package can be found.',
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'patch_description_url' => array(
+        'description' => 'The (optional) URL where a patch file applied to a package is described.',
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'patch_nid' => array(
+        'description' => 'The (optional) {node}.nid of a node on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+      'patch_comment_id' => array(
+        'description' => 'The (optional) {comment}.cid of a comment on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('package_nid', array('patch_file_url', 255)),
+  );
+
   return $schema;
 }
 
+/**
+ * Add tables for remote items (or libraries) and patches to releases and remote items.
+ */
+function project_package_update_6001(&$sandbox) {
+  $ret = array();
+
+  $remote_item_schema = array(
+    'description' => 'Keeps track of what remote items (or libraries) are included in a release of a given package project.',
+    'fields' => array(
+      'id' => array(
+        'description' => 'The primary identifier for a remote item.',
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE
+      ),
+      'package_nid' => array(
+        'description' => 'Primary Key: The {node}.nid of the package release node.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'name' => array(
+        'description' => 'A name to describe this remote item.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'url' => array(
+        'description' => 'The URL of a remote item (or library) included as an item in the package.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'primary key' => array('id'),
+    'indexes' => array('project_package_remote_item_package_nid' => array('package_nid')),
+  );
+
+  db_create_table($ret, 'project_package_remote_item', $remote_item_schema);
+
+  $local_patch_schema = array(
+    'description' => 'Keeps track of any patches that are applied in a release of a given package project.',
+    'fields' => array(
+      'package_nid' => array(
+        'description' => 'Primary Key: The {node}.nid of the package release node.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'item_nid' => array(
+        'description' => 'The {node}.nid of a local release node (from the same site) that was patched.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'patch_file_url' => array(
+        'description' => 'The URL where a given patch file applied to a package can be found.',
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'patch_description_url' => array(
+        'description' => 'The (optional) URL where a patch file applied to a package is described.',
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'patch_nid' => array(
+        'description' => 'The (optional) {node}.nid of a node on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+      'patch_comment_id' => array(
+        'description' => 'The (optional) {comment}.cid of a comment on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('package_nid', array('patch_file_url', 255)),
+  );
+
+  db_create_table($ret, 'project_package_local_patch', $local_patch_schema);
+
+  $remote_patch_schema = array(
+    'description' => 'Keeps track of any patches that are applied in a release of a given package project.',
+    'fields' => array(
+      'package_nid' => array(
+        'description' => 'Primary Key: The {node}.nid of the package release node.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'remote_id' => array(
+        'description' => 'The {project_package_remote_item}.id of a remote item (or library) that was patched.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'patch_file_url' => array(
+        'description' => 'The URL where a given patch file applied to a package can be found.',
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+      'patch_description_url' => array(
+        'description' => 'The (optional) URL where a patch file applied to a package is described.',
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'patch_nid' => array(
+        'description' => 'The (optional) {node}.nid of a node on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+      'patch_comment_id' => array(
+        'description' => 'The (optional) {comment}.cid of a comment on this site that describes a patch file applied to a package.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+    ),
+    'primary key' => array('package_nid', array('patch_file_url', 255)),
+  );
+
+  db_create_table($ret, 'project_package_remote_patch', $remote_patch_schema);
+
+  return $ret;
+}
diff --git a/package/project_package.module b/package/project_package.module
index 42adc73..91e5e99 100644
--- a/package/project_package.module
+++ b/package/project_package.module
@@ -50,6 +50,8 @@ function project_package_release_nodeapi(&$node, $op, $arg) {
         $node->project_package['count'] = $count;
       }
       break;
+    case 'delete':
+      project_package_clear_release_items($node->nid);
       
   }
 }
@@ -81,3 +83,111 @@ function project_package_check_update_status($item_nids) {
   }
 }
 
+/**
+ * Record a patch file included in a given release package.
+ *
+ * @param integer $package_nid
+ *   The release node ID of the package to record the patch information for.
+ * 
+ * @param string $patch_url
+ *   The fully qualified URL where the patch file lives.
+ *
+ * @param integer $item_id
+ *   The local release item ID, or remote item ID to which the patch applies.
+ *
+ *   This id references either {project_package_local_release_item}.item_nid or
+ *   {project_package_remote_item}.id.
+ *
+ * @param string $item_type
+ *   The type of item to which the patch is applied. Either 'local' or 'remote'.
+ * 
+ *   Items marked 'local', correspond to items recorded in
+ *   {project_package_local_release_item} and items marked as 'remote'
+ *   correspond with items recorded in {project_package_remote_item}.
+ */
+function project_package_record_patch($package_nid, $patch_url, $item_id, $item_type) {
+  global $base_url;
+
+  // See if the patch URL is a local patch
+  $url = parse_url($patch_url);
+  $local_url = parse_url($base_url);
+  $local = ($url['host'] == $local_url['host']);
+
+  // If it is local, see if the patch is attached to a node or comment.
+  $patch_issue = array();
+  if ($local) {
+    $filepath = substr($url['path'], 1);
+    // Check if the file is attached to an issue with comment_upload.
+    $related_issue = db_fetch_object(db_query("SELECT n.nid as nid, n.title as title, cu.cid as cid FROM {files} f LEFT JOIN {comment_upload} cu ON f.fid = cu.fid LEFT JOIN {node} n ON cu.nid = n.nid WHERE filepath = '%s' LIMIT 1", $filepath));
+
+    if ($related_issue) {
+      $patch_issue['nid'] = $related_issue->nid;
+      $patch_issue['cid'] = $related_issue->cid;
+      $patch_issue['description'] = $related_issue->title;
+    }
+
+    // Check if the file is attached to a regular node with upload module.
+    if (!isset($patch_issue['nid'])) {
+      $node = db_fetch_object(db_query("SELECT n.nid as nid, n.title as title FROM files f LEFT JOIN upload u ON f.fid = u.fid LEFT JOIN node n ON u.nid = n.nid WHERE filepath = '%s'", $filepath));
+      if ($node) {
+        $patch_issue['nid'] = $node->nid;
+        $patch_issue['description'] = $node->title;
+      }
+    }
+  }
+
+  // Finally, save a record into {project_package_(remote|local)_patch}.
+  $table = "project_package_{$item_type}_patch";
+  $item_column = ($item_type == 'local') ? 'item_nid' : 'remote_id';
+  
+  // Try to update an existing record, if any.
+  db_query("UPDATE {%s} SET %s = %d, patch_description_url = '%s', patch_nid = %d, patch_comment_id = %d WHERE package_nid = %d AND patch_file_url = '%s'", $table, $item_column, $item_id, $patch_issue['description'], $patch_issue['nid'], $patch_issue['cid'], $package_nid, $patch_url);
+  if (!db_affected_rows()) {
+    // Didn't update anything, add this as a record, instead.
+    @db_query("INSERT INTO {%s} (package_nid, %s, patch_file_url, patch_description_url, patch_nid, patch_comment_id) VALUES (%d, %d, '%s', '%s', %d, %d)", $table, $item_column, $package_nid, $item_id, $patch_url, $patch_issue['description'], $patch_issue['nid'], $patch_issue['cid']);
+  }
+}
+
+/**
+ * Record a remote item (or library) included in a given release.
+ *
+ * @param integer $package_nid
+ *   The release node ID of the package to record the patch information for.
+ *
+ * @param string $patch_url
+ *   The fully qualified URL where the patch file lives.
+ *
+ * @param string $name
+ *   A human readable name to be associated with the item.
+ */
+function project_package_record_remote_item($package_nid, $item_url, $name) {
+  // Try to update an existing record, if any.
+  $record = (object) array(
+    'package_nid' => $package_nid,
+    'url' => $item_url,
+    'name' => $name,
+  );
+
+  $id = db_result(db_query("SELECT id FROM {project_package_remote_item} WHERE package_nid = %d AND url = '%s'", $record->package_nid, $record->url));
+  if ($id) {
+    $record->id = $id;
+    $update = array('id');
+  }
+  else {
+    $update = array();
+  }
+
+  drupal_write_record('project_package_remote_item', $record, $update);
+
+  return $record->id;
+}
+
+/**
+ * Remove all records containing package contents for a release node.
+ */
+function project_package_clear_release_items($nid) {
+  db_query("DELETE FROM project_package_local_release_item WHERE package_nid = %d", $nid);
+  db_query("DELETE FROM project_package_remote_item WHERE package_nid = %d", $nid);
+  db_query("DELETE FROM project_package_local_patch WHERE package_nid = %d", $nid);
+  db_query("DELETE FROM project_package_remote_patch WHERE package_nid = %d", $nid);
+}
