diff --git a/context_by_node.info b/context_by_node.info
index 2cc9870..1c70601 100644
--- a/context_by_node.info
+++ b/context_by_node.info
@@ -3,5 +3,7 @@ description = "Automatically generates a Context for every Node"
 package = "Context Extras"
 dependencies[] = context
 dependencies[] = context_ui
-dependencies[] = cep_node
-core = 6.x
+core = 7.x
+files[] = context_by_node.install
+files[] = context_by_node.module
+project = "context_by_node"
\ No newline at end of file
diff --git a/context_by_node.install b/context_by_node.install
index f9d9aeb..a3f7192 100644
--- a/context_by_node.install
+++ b/context_by_node.install
@@ -5,7 +5,7 @@
  */
 
 /**
- * Implements hook_schema_alter()
+ * Implements hook_schema_alter().
  */
 function context_by_node_schema_alter(&$schema) {
   $schema['context']['fields']['hidden'] = array(
@@ -17,7 +17,7 @@ function context_by_node_schema_alter(&$schema) {
 }
 
 /**
- * Implements hook_install()
+ * Implements hook_install().
  */
 function context_by_node_install() {
   // Clear the schema cache and rebuild
@@ -27,25 +27,26 @@ function context_by_node_install() {
   context_by_node_schema_alter($schema);
 
   // Add the new Column
-  $ret = array();
-  db_add_field($ret, 'context', 'hidden', $schema['context']['fields']['hidden']);
+  db_add_field('context', 'hidden', $schema['context']['fields']['hidden']);
 
   // If already exist some contexts generated by this module we must hidde them again
-  db_query('UPDATE {context} SET hidden=1 WHERE tag="%s"', 'Context by Node');
+  db_update('context')
+    ->fields(array(
+      'hidden' => 1,
+    ))
+    ->condition('tag', 'Context by Node')
+    ->execute();
 
   // Set the Content Type "Page" for default
   variable_set('context_by_node_content_types', array('page'));
 }
 
 /**
- * Implements hook_uninstall()
+ * Implements hook_uninstall().
  */
 function context_by_node_uninstall() {
-  $ret = array();
-  db_drop_field($ret, 'context', 'hidden');
+  db_drop_field('context', 'hidden');
 
   variable_del('context_by_node_content_types');
   variable_del('context_by_node_hide_context_ui_admin');
 }
-
- 
\ No newline at end of file
diff --git a/context_by_node.module b/context_by_node.module
index bab0d58..f8ccd94 100644
--- a/context_by_node.module
+++ b/context_by_node.module
@@ -1,78 +1,80 @@
 <?php
 
-//include_once drupal_get_path('module', 'context') .'/context.module';
+include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'context') . '/context.module';
 
 /**
- * Implements hook_perms()
+ * Implements hook_permission().
  */
-function context_by_node_perm() {
+function context_by_node_permission() {
   return array(
-    'create context_by_node',
+    'create context_by_node' => array(
+      'title' => t('create context_by_node'),
+      'description' => t('Allow users to create a context per node.'),
+    ),
   );
 }
 
 /**
- * Implements hook_nodeapi()
+ * Implements hook_node_insert().
  */
-function context_by_node_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-
-  // Content Types where Context by Node is enabled
-  if (in_array($node->type, variable_get('context_by_node_content_types', array()))) {
-    switch ($op) {
-      case 'insert':
-      case 'update':
-        if (!empty($node->context_by_node_create)) {
-          _context_by_node_create_context($node);
-        }
-        else {
-          _context_by_node_delete_context($node);
-        }
-      break;
-
-      case 'delete':
-        _context_by_node_delete_context($node);
-      break;
-    }
+function context_by_node_node_insert($node){
+  if (!isset($node->context_by_node_create))  {
+    return;
+  }
+  elseif ($node->context_by_node_create == 1) {
+    context_by_node_create($node);
   }
 }
 
 /**
- * Helper function, creates and saves the Context by Node if it doesn't exists.
- * 
- * @param object $node
+ * Implements hook_node_update().
+ */
+function context_by_node_node_update($node){
+  if (!isset($node->context_by_node_create))  {
+    return;
+  }  
+  elseif ($node->context_by_node_create == 1) {
+    context_by_node_create($node);
+  }
+  elseif ($node->context_by_node_create == 0) {
+    context_by_node_delete($node);
+  }  
+}
+
+/**
+ * If not already created, creates a context for a given node.
  */
-function _context_by_node_create_context($node) {
+function context_by_node_create($node) {
   if (!context_by_node_exist($node->nid)) {
-    
     // Create the new Context
     $context = new stdClass();
     $context->reactions = array();
     $context->condition_mode = 0;
     $context->hidden = 1;
     $context->name = 'context_by_node_' . $node->nid;
-    $context->description = t('Context by Node [nid:@nid]', array('@nid' => $node->nid));
+    $context->description = t('Page context', array('@nid' => $node->nid));
     $context->tag = 'Context by Node';
     $context->conditions = array(
-      'cep_node' => array(
-        'values' => array($node->nid),
-        'options' => 0,
+      'path' => array(
+        'values' => array(
+          'node/' . $node->vid => 'node/' . $node->vid,
+        ),
       ),
     );
-
     context_save($context);
   }
 }
 
 /**
- * Helper function, deletes Context by Node for the given node.
+ * Implements of hook_node_delete().
  *
- * @param object $node
+ * Removes the context associated with the node being deleted.
  */
-function _context_by_node_delete_context($node) {
-  if ($context_name = context_by_node_get_name($node->nid)) {
-    db_query("DELETE FROM {context} WHERE name = '%s'", $context_name);
-    
-    // Clear Context's cache
+function context_by_node_delete($node) {
+  if ($context = context_by_node_exist($node->nid)) {
+    db_delete('context')
+      ->condition('name', 'context_by_node_' . $node->nid)
+      ->execute();
     context_invalidate_cache();
   }
 }
@@ -87,27 +89,29 @@ function context_by_node_form_alter(&$form, &$form_state, $form_id) {
   // NODE FORM:
   // Get the enabled content types; if the content type is enabled we add the field.
   if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id && user_access('create context_by_node')) {
-      
+
     $content_types = variable_get('context_by_node_content_types', array());
 
     if (isset($content_types[$form['type']['#value']]) && !empty($content_types[$form['type']['#value']])) {
-      
+
       $form['context_by_node'] = array(
         '#title' => t('Context by Node'),
         '#type' => 'fieldset',
         '#collapsible' => TRUE,
         '#collapsed' => TRUE,
+        '#group' => 'additional_settings',
       );
 
-      // Get the Context
-      $exist_context_by_node = context_by_node_exist($form['nid']['#value']);
-  
+      // Get the Context.
+      $exist_context_by_node = (context_by_node_exist($form['nid']['#value']) ? TRUE : FALSE);
+
       $checkbox_title = t('Create Context for this Node');
 
-      // Uncheck for delete the Context and a link to edit the context
+      // Uncheck for delete the Context and a link to edit the context.
       if (!empty($form['nid']['#value']) && is_numeric($form['nid']['#value']) && $exist_context_by_node) {
         $context_id = 'context_by_node_' . $form['nid']['#value'];
-        $edit_link = l(t('Edit context'), 'admin/build/context/list/' . $context_id . '/edit', array('query' => drupal_get_destination()));
+        $edit_link = l(t('Edit context'), 'admin/structure/context/list/' . $context_id . '/edit', array('query' => drupal_get_destination()));
+
         $checkbox_title = t('Uncheck to remove the Context') . ' | ' . $edit_link;
       }
 
@@ -118,9 +122,9 @@ function context_by_node_form_alter(&$form, &$form_state, $form_id) {
       );
     }
   }
-  
+
   // CONTEXT SETTINGS FORM:
-  // Choose what content types want to enable
+  // Choose what content types want to enable.
   if ($form_id == 'context_ui_settings') {
 
     $form['context_by_node'] = array(
@@ -137,10 +141,10 @@ function context_by_node_form_alter(&$form, &$form_state, $form_id) {
 
     $form['context_by_node']['context_by_node_content_types'] = array(
       '#title' => t('Enabled Content types'),
-      '#description' => t('In the case you disable a content type it <b>will not delete any context</b> generated by this module.<br />Must preserve your content.'),
+      '#description' => t('In the case you disable a content type it <strong>will not delete any context</strong> generated by this module.<br />Must preserve your content.'),
       '#type' => 'checkboxes',
       '#default_value' => variable_get('context_by_node_content_types', array()),
-      '#options' => node_get_types('names'),
+      '#options' => node_type_get_names(),
     );
   }
 }
@@ -155,9 +159,13 @@ function context_by_node_form_alter(&$form, &$form_state, $form_id) {
 function context_by_node_get_name($nid) {
   $context = FALSE;
   if ($nid > 0) {
-    $context_name = db_result(db_query("SELECT name FROM {context} WHERE name='%s'", 'context_by_node_' . $nid));
+    $context = db_select('context','c')
+      ->fields('c',array('name'))
+      ->condition('name', 'context_by_node_' . $nid, '=')
+      ->execute()
+      ->fetchAssoc();
   }
-  return $context_name;
+  return $context;
 }
 
 /**
@@ -171,7 +179,7 @@ function context_by_node_exist($nid) {
 }
 
 /**
- * Implements hook_export_load_all()
+ * Implements hook_export_load_all().
  * 
  * Callback for the load list of the Export UI for Context
  */
@@ -180,6 +188,5 @@ function context_by_node_export_load_all($reset) {
   if (variable_get('context_by_node_hide_context_ui_admin', 0)) {
     $condition['hidden'] = 0;
   }
-
   return ctools_export_load_object('context', 'conditions', $condition);
 }
