diff --git a/context_og.info b/context_og.info
index 624d555..e6ec1fb 100644
--- a/context_og.info
+++ b/context_og.info
@@ -1,7 +1,7 @@
 name = Context OG
 description = "Provides Organic Groups conditions and reactions for the Context module."
 package = "Context"
-core = "6.x"
+core = "7.x"
 dependencies[] = og
 dependencies[] = views
 dependencies[] = og_views
diff --git a/context_og.module b/context_og.module
index d3dccd2..4192092 100644
--- a/context_og.module
+++ b/context_og.module
@@ -63,15 +63,28 @@ function context_og_context_registry() {
 }
 
 /**
- * Implementation of hook_context_page_condition().
+ * TODO The call order of the plugins has been reversed here (which arguably is
+ * confusing).
+ * The hook_context_page_reaction() sets up our condition plugins and the the
+ * hook_context_page_condition() sets up our reaction.
+ * This had to be done because we need the hooks in the following order:
+ *
+ * 1. OG hooks (to set context)
+ * 2. context_og reaction (so our conditions can work with it)
+ * 3. context_og condition
+ */
+
+
+/*
+ * Implementation of hook_context_page_reaction().
  * 
  * This needs to run after Organic Groups' hook_init() because we need the group context to be set.
  * 
  * It also needs to run after Views processes arguments because og_views provides argument handlers
  * that set OG's group context.
  */
-function context_og_context_page_condition() {
-  $group = og_get_group_context();
+function context_og_context_page_reaction() {
+  $group = og_context();
 
   // Only execute the group node context condition if there is a group node
   // in context.
@@ -91,15 +104,38 @@ function context_og_context_page_condition() {
 }
 
 /**
- * Implementation of hook_init().
- *
  * Execute the "set group context" reaction here so that our conditions will work
  * when they get executed.  We want to come after organic groups' hook_init() so
  * the context doesn't get switched out from under us.
  */
-function context_og_init() {
+function context_og_context_page_condition() {
   $plugin = context_get_plugin('reaction', 'context_og_reaction_set_group_context');
+
   if ($plugin) {
     $plugin->execute();
   }
 }
+
+/**
+ * Helper function
+ * query all created nodes that are of a group type
+ *
+ * @return an executed query object to iterate
+ */
+function context_og_query_og_nodes() {
+  $query = db_select('node', 'n')
+    ->fields('n', array('nid', 'title', 'type'));
+
+  $query
+    ->join('og', 'o', 'n.nid = o.etid');
+
+  $query
+    ->fields('o', array('gid'))
+    ->orderBy('n.type')
+    ->orderBy('n.title')
+    ->addTag('node_access');
+
+  $result = $query->execute();
+
+  return $result;
+}
diff --git a/plugins/context_og_condition_group_node.inc b/plugins/context_og_condition_group_node.inc
index e87fbd9..f9bb48f 100644
--- a/plugins/context_og_condition_group_node.inc
+++ b/plugins/context_og_condition_group_node.inc
@@ -5,12 +5,13 @@
  */
 class context_og_condition_group_node extends context_condition {
   function condition_values() {
-    $sql = "SELECT n.nid, n.title, n.type FROM {node} n INNER JOIN {og} o ON n.nid = o.nid ORDER BY n.type, n.title";
-    $result = db_query(db_rewrite_sql($sql));
+    $result = context_og_query_og_nodes();
 
     $values = array();
-    while ($group = db_fetch_object($result)) {
-      $type = node_get_types('name', $group->type);
+
+    foreach ($result as $group) {
+      $type = node_type_get_name($group->type);
+
       $values[$group->nid] = $type . ': ' . $group->title;
     }
 
@@ -39,14 +40,15 @@ class context_og_condition_group_node extends context_condition {
   function execute($group) {
     if (isset($group)) {
       $node_form = ((arg(0) == 'node') && ((is_numeric(arg(1)) && (arg(2) == 'edit')) || (arg(1) == 'add')));
-      $contexts = $this->get_contexts($group->nid);
-      $this->values[$group->nid] = array();
+      $contexts = $this->get_contexts($group->etid);
+      $this->values[$group->etid] = array();
+
       foreach ($contexts as $context) {
         $options = $this->fetch_from_context($context, 'options');
         // The condition is met unless we are looking at a node form
         // and the "Set on node form" option is unchecked.
         if (!$node_form || !empty($options['node_form'])) {
-          $this->condition_met($context, $group->nid);
+          $this->condition_met($context, $group->etid);
         }
       }
     }
diff --git a/plugins/context_og_condition_group_type.inc b/plugins/context_og_condition_group_type.inc
index 61bc39b..2ad4dae 100644
--- a/plugins/context_og_condition_group_type.inc
+++ b/plugins/context_og_condition_group_type.inc
@@ -6,9 +6,8 @@
 class context_og_condition_group_type extends context_condition {
   function condition_values() {
     $values = array('_none_' => t('Not in a group'));
-    $og_types = og_get_types('group');
-    foreach (node_get_types() as $type) {
-      if (in_array($type->type, $og_types)) {
+    foreach (node_type_get_types() as $type) {
+      if (og_is_group_type('node', $type->type)) {
         $values[$type->type] = $type->name;
       }
     }
@@ -28,10 +27,12 @@ class context_og_condition_group_type extends context_condition {
   }
 
   function execute($group) {
-    $type = isset($group) ? $group->type : '_none_';
+    $node = $group ? node_load($group->etid) : FALSE;
+    $type = $node ? $node->type : '_none_';
     $node_form = ((arg(0) == 'node') && ((is_numeric(arg(1)) && (arg(2) == 'edit')) || (arg(1) == 'add')));
     $contexts = $this->get_contexts($type);
     $this->values[$type] = array();
+
     foreach ($contexts as $context) {
       $options = $this->fetch_from_context($context, 'options');
       // The condition is met unless we are looking at a node form
diff --git a/plugins/context_og_reaction_set_group_context.inc b/plugins/context_og_reaction_set_group_context.inc
index b8c6281..e2af262 100644
--- a/plugins/context_og_reaction_set_group_context.inc
+++ b/plugins/context_og_reaction_set_group_context.inc
@@ -8,13 +8,13 @@ class context_og_reaction_set_group_context extends context_reaction {
    * Choose a group whose OG context will be set for this reaction.
    */
   function options_form($context) {
-    $sql = "SELECT n.nid, n.title, n.type FROM {node} n INNER JOIN {og} o ON n.nid = o.nid ORDER BY n.type, n.title";
-    $result = db_query(db_rewrite_sql($sql));
-
+    $result = context_og_query_og_nodes();
     $options = array();
-    while ($group = db_fetch_object($result)) {
-      $type = node_get_types('name', $group->type);
-      $options[$group->nid] = $type . ': ' . $group->title;
+
+    foreach ($result as $group) {
+      $type = node_type_get_name($group->type);
+
+      $options[$group->gid] = $type . ': ' . $group->title;
     }
 
     $values = $this->fetch_from_context($context);
@@ -34,12 +34,12 @@ class context_og_reaction_set_group_context extends context_reaction {
 
   function execute() {
     $contexts = context_active_contexts();
-    $classes = array();
+    //dpm($contexts);
 
     foreach ($contexts as $k => $v) {
       if (!empty($v->reactions[$this->plugin]['group'])) {
-        $group_node = node_load(array('nid' => $v->reactions[$this->plugin]['group']));
-        og_set_group_context($group_node);
+        $group = og_load($v->reactions[$this->plugin]['group']);
+        og_context($group);
       }
     }
   }
