diff --git a/private.info b/private.info
index 052ca31..e95c72b 100644
--- a/private.info
+++ b/private.info
@@ -1,3 +1,11 @@
 name = Private
 description = Allows users to mark content as private, and hide that content from visitors.
-core = 6.x
+core = 7.x
+version = "7.x-1.x-dev"
+project = "private"
+datestamp = "1298619980"
+
+files[] = private.install
+files[] = private.module
+files[] = private.views.inc
+files[] = private_handler_filter_private.inc
diff --git a/private.install b/private.install
index 6bdd309..bfe0ce1 100644
--- a/private.install
+++ b/private.install
@@ -1,5 +1,14 @@
 <?php
+/**
+ * @file
+ * Install, update and uninstall functions for the private module.
+ *
+ */
 
+
+/**
+ * Implements hooks_schema().
+ */
 function private_schema() {
   $schema['private'] = array(
     'fields' => array(
@@ -8,14 +17,6 @@ function private_schema() {
     ),
     'primary key' => array('nid'),
   );
-  
-  return $schema;
-}
 
-function private_install() {
-  drupal_install_schema('private');
-}
-
-function private_uninstall() {
-  drupal_uninstall_schema('private');
+  return $schema;
 }
diff --git a/private.module b/private.module
index 25336f5..da2ae15 100644
--- a/private.module
+++ b/private.module
@@ -13,7 +13,7 @@ define('PRIVATE_AUTOMATIC', 2);
 define('PRIVATE_ALWAYS', 3);
 
 /**
- * Implementation of hook_enable().
+ * Implements hook_enable().
  *
  * A node access module needs to force a rebuild of the node access table
  * when it is enabled to ensure that things are set up.
@@ -23,7 +23,7 @@ function private_enable() {
 }
 
 /**
- * Implementation of hook_disable().
+ * Implements hook_disable().
  *
  * A node access module needs to force a rebuild of the node access table
  * when it is disabled to ensure that its entries are removed from the table.
@@ -46,17 +46,30 @@ function private_disabling($set = NULL) {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  *
  * In this example, we will use a simple permission to determine whether a user
  * has access to "private" content. This permission is defined here.
  */
-function private_perm() {
-  return array('mark content as private', 'access private content', 'edit private content');
+function private_permission() {
+  return array(
+    'mark content as private' => array(
+      'title' => t('Mark content as private'),
+      'description' => t('Make content only viewable by people with access to view private content'),
+    ),
+    'access private content' => array(
+      'title' => t('Access private content'),
+      'description' => t('Access any content marked as private'),
+    ),
+    'edit private content' => array(
+      'title' => t('Edit private content'),
+      'description' => t('Edit content marked as private'),
+    ),
+  );
 }
 
 /**
- * Implementation of hook_node_grants().
+ * Implements hook_node_grants().
  *
  * Tell the node access system what GIDs the user belongs to for each realm.
  * In this example, we are providing two realms: the example realm, which
@@ -82,7 +95,7 @@ function private_node_grants($account, $op) {
 }
 
 /**
- * Implementation of hook_node_access_records().
+ * Implements hook_node_access_records().
  *
  * All node access modules must implement this hook. If the module is
  * interested in the privacy of the node passed in, return a list
@@ -101,10 +114,10 @@ function private_node_access_records($node) {
     $grants = array();
     $grants[] = array(
       'realm' => 'private',
-      'gid' => TRUE,
-      'grant_view' => TRUE,
-      'grant_update' => FALSE,
-      'grant_delete' => FALSE,
+      'gid' => 1,
+      'grant_view' => 1,
+      'grant_update' => 0,
+      'grant_delete' => 0,
       'priority' => 0,
     );
 
@@ -113,9 +126,9 @@ function private_node_access_records($node) {
     $grants[] = array(
       'realm' => 'private_author',
       'gid' => $node->uid,
-      'grant_view' => TRUE,
-      'grant_update' => TRUE,
-      'grant_delete' => TRUE,
+      'grant_view' => 1,
+      'grant_update' => 1,
+      'grant_delete' => 1,
       'priority' => 0,
     );
     return $grants;
@@ -123,16 +136,17 @@ function private_node_access_records($node) {
 }
 
 /**
- * Implementation of hook_form_alter()
+ * Implements hook_form_alter().
  *
  * This module adds a simple checkbox to the node form labeled private. If the
  * checkbox is labelled, only the node author and users with 'access private content'
  * privileges may see it.
  */
 function private_form_alter(&$form, $form_state, $form_id) {
-  if ($form['#id'] == 'node-form') {
+  #drupal_set_message('<pre>'.var_export($form,1).'</pre>');
+  if (isset($form['#node_edit_form'])) {
     $node = $form['#node'];
-    $default = variable_get('private_'. $node->type, PRIVATE_ALLOWED);
+    $default = variable_get('private_' . $node->type, PRIVATE_ALLOWED);
 
     if ($default != PRIVATE_DISABLED || !empty($node->privacy)) {
       if (empty($node->nid)) {
@@ -159,8 +173,8 @@ function private_form_alter(&$form, $form_state, $form_id) {
       }
     }
   }
-  elseif($form_id == 'node_type_form') {
-    $node_type = (array)$form['#node_type'];
+  elseif ($form_id == 'node_type_form') {
+    $node_type = (array) $form['#node_type'];
     $type = $node_type['type'];
     $form['workflow']['private'] = array(
       '#type' => 'radios',
@@ -171,87 +185,140 @@ function private_form_alter(&$form, $form_state, $form_id) {
         PRIVATE_AUTOMATIC => t('Enabled (private by default)'),
         PRIVATE_ALWAYS => t('Hidden (always private)'),
       ),
-      '#default_value' => variable_get('private_'. $type, PRIVATE_ALLOWED),
+      '#default_value' => variable_get('private_' . $type, PRIVATE_ALLOWED),
     );
   }
 }
 
 /**
- * Implementation of hook_nodeapi().
- *
- * - "delete", "insert", and "update":
- * The module must track the access status of the node.
+ * Implements hook_node_load().
  */
-function private_nodeapi(&$node, $op, $arg = 0) {
-  switch ($op) {
-    case 'load':
-      $result = db_fetch_object(db_query('SELECT * FROM {private} WHERE nid = %d', $node->nid));
-      $node->private = $result->private;
-      break;
-    case 'delete':
-      db_query('DELETE FROM {private} WHERE nid = %d', $node->nid);
-      break;
-    case 'insert':
-    case 'update':
-      db_query('UPDATE {private} SET private = %d WHERE nid = %d', $node->private, $node->nid);
-      if (!db_affected_rows()) {
-        db_query('INSERT INTO {private} (nid, private) VALUES (%d, %d)', $node->nid, $node->private);
-      }
-      break;
+function private_node_load($nodes, $types) {
+  $result = db_query('SELECT * FROM {private} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
+  foreach ($result as $record) {
+    $nodes[$record->nid]->private = $record->private;
+  }
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+function private_node_delete($node) {
+  db_delete('private')
+  ->condition('nid', $node->nid)
+  ->execute();
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function private_node_insert($node) {
+  $num_updated = db_update('private')
+  ->fields(array(
+    'private' => $node->private,
+  ))
+  ->condition('nid', $node->nid)
+  ->execute();
+  if (!$num_updated) {
+    $id = db_insert('private')
+    ->fields(array(
+      'nid' => $node->nid,
+      'private' => $node->private,
+    ))
+    ->execute();
   }
 }
 
 /**
-* Implementation of hook_file_download().
-*/
+ * Implements hook_node_update().
+ */
+function private_node_update($node) {
+  $num_updated = db_update('private')
+  ->fields(array(
+    'private' => $node->private,
+  ))
+  ->condition('nid', $node->nid)
+  ->execute();
+  if (!$num_updated) {
+    $id = db_insert('private')
+    ->fields(array(
+      'nid' => $node->nid,
+      'private' => $node->private,
+    ))
+    ->execute();
+  }
+}
+
+/**
+ * Implements hook_file_download().
+ */
 function private_file_download($file) {
-  $file = file_create_path($file);
-  $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
-  if ($file = db_fetch_object($result)) {
-    $node = node_load($file->nid);
-    if ($node->private == 1) {
-        if (node_access('view', $node) == FALSE) {
-            return -1;
+  $file = file_prepare_directory($file);
+  $result = db_query("SELECT f.* FROM {files} f WHERE filepath = :filepath", array(':filepath' => $file));
+  foreach ($result as $record){
+      if($record){
+        $node = node_load($record->nid);
+        if ($node->private == 1) {
+            if (node_access('view', $node) == FALSE) {
+                return -1;
+            }
         }
       }
   }
 }
 
-function private_link($type, $node = NULL, $teaser = FALSE) {
-  if ($type == 'node' && $node->private) {
-    $links['private_icon']['title'] = theme('private_node_link', $node);
-    $links['private_icon']['html'] = TRUE;
-    return $links;
-  }
+/**
+ * Implements hook_node_view().
+ */
+function private_node_view($node, $view_mode){
+    if($node->private){
+        $links['private_icon']['title'] = theme('private_node_link', array('node' => $node));
+        $links['private_icon']['html'] = TRUE;
+        $node->content['links'][$node->type] = array(
+            '#theme' => 'links__node__' . $node->type,
+            '#links' => $links,
+            '#attributes' => array('class' => array('links', 'inline')),
+      );
+    }
 }
 
+/**
+ * Implements hook_theme().
+ */
 function private_theme() {
-  return array('private_node_link' => array('arguments' => array('node' => NULL)));
+  return array('private_node_link' => array('variables' => array('node' => NULL)));
 }
 
-function theme_private_node_link($node) {
-  return theme('image', drupal_get_path('module', 'private') . '/icon_key.gif', t('Private'), t('This content is private'));
+/**
+ * Custom theme function
+ * @see private_theme()
+ */
+function theme_private_node_link($variables) {
+  $node = $variables['node'];
+  return theme('image', array('path' => drupal_get_path('module', 'private') . '/icon_key.gif', 'width' => t('Private'), 'height' => t('This content is private')));
 }
 
 /**
- * Implementation of hook_action_info().
+ * Implements hook_action_info().
  */
 function private_action_info() {
   return array(
     'private_set_private_action' => array(
       'type' => 'node',
-      'description' => t('Make post private'),
+      'label' => t('Make post private'),
       'configurable' => FALSE,
-      'hooks' => array(
-        'nodeapi' => array('insert', 'update'),
+      'triggers' => array(
+        'nodeapi_insert',
+        'nodeapi_update',
       ),
     ),
     'private_set_public_action' => array(
       'type' => 'node',
-      'description' => t('Make post public'),
+      'label' => t('Make post public'),
       'configurable' => FALSE,
-      'hooks' => array(
-        'nodeapi' => array('insert', 'update'),
+      'triggers' => array(
+        'nodeapi_insert',
+        'nodeapi_update',
       ),
     ),
   );
@@ -278,7 +345,7 @@ function private_set_private_action(&$node, $context = array()) {
 }
 
 /**
- * Implementation of hook_node_operations().
+ * Implements hook_node_operations().
  */
 function private_node_operations() {
   $operations = array(
@@ -299,9 +366,19 @@ function private_node_operations() {
  */
 function private_node_mark_private($nids) {
   foreach ($nids as $nid) {
-    db_query('UPDATE {private} SET private = %d WHERE nid = %d', 1, $nid);
-    if (!db_affected_rows()) {
-      db_query('INSERT INTO {private} (nid, private) VALUES (%d, %d)', $nid, 1);
+    $num_updated = db_update('private')
+    ->fields(array(
+      'private' => 1,
+    ))
+    ->condition('nid', $nid)
+    ->execute();
+    if (!$num_updated) {
+      $id = db_insert('private')
+        ->fields(array(
+        'nid' => $nid,
+        'private' => 1,
+        ))
+        ->execute();
     }
   }
 }
@@ -311,9 +388,19 @@ function private_node_mark_private($nids) {
  */
 function private_node_mark_public($nids) {
   foreach ($nids as $nid) {
-    db_query('UPDATE {private} SET private = %d WHERE nid = %d', 0, $nid);
-    if (!db_affected_rows()) {
-      db_query('INSERT INTO {private} (nid, private) VALUES (%d, %d)', $nid, 0);
+    $num_updated = db_update('private')
+    ->fields(array(
+      'private' => 0,
+    ))
+    ->condition('nid', $nid)
+    ->execute();
+    if (!$num_updated) {
+      $id = db_insert('private')
+        ->fields(array(
+        'nid' => $nid,
+        'private' => 0,
+        ))
+        ->execute();
     }
   }
 }
@@ -326,4 +413,4 @@ function private_views_api() {
     'api' => 2,
     'path' => drupal_get_path('module', 'private'),
   );
-}
\ No newline at end of file
+}
diff --git a/private.views.inc b/private.views.inc
index 45dd9ee..2215477 100644
--- a/private.views.inc
+++ b/private.views.inc
@@ -1,5 +1,8 @@
 <?php
 
+/**
+ * Implements hook_views_data().
+ */
 function private_views_data() {
   $data = array();
 
@@ -34,6 +37,9 @@ function private_views_data() {
 
 }
 
+/**
+ * Implements hook_views_handlers().
+ */
 function private_views_handlers() {
   return array(
     'info' => array(
diff --git a/private_handler_filter_private.inc b/private_handler_filter_private.inc
index 7973c8a..5f5b6a4 100644
--- a/private_handler_filter_private.inc
+++ b/private_handler_filter_private.inc
@@ -8,7 +8,7 @@ class private_handler_filter_private extends views_handler_filter_boolean_operat
 
   function query() {
     $this->ensure_my_table();
-    $qualified_name = "$this->table_alias.$this->real_field"; 
+    $qualified_name = "$this->table_alias.$this->real_field";
     $this->query->add_where($this->options['group'], $qualified_name . (empty($this->value) ? " = 0 OR $qualified_name IS NULL" : ' = 1'));
   }
 }
