diff --git a/panels_ajax_tab.module b/panels_ajax_tab.module
index bd65e58..b5aa6f7 100644
--- a/panels_ajax_tab.module
+++ b/panels_ajax_tab.module
@@ -172,7 +172,8 @@ function panels_ajax_tab_get_context($context_string) {
   $parts = explode(':', $context_string);
   $entity_type = strtolower($parts[0]);
   $entity_id = (int) $parts[1];
-  $entity = array_pop(entity_load($entity_type, array($entity_id)));
+  $entity = entity_load($entity_type, array($entity_id));
+  $entity = array_pop($entity);
   $entity->entity_type = $entity_type;
   return $entity;
 }
diff --git a/plugins/content_types/panels_ajax_tab_container.inc b/plugins/content_types/panels_ajax_tab_container.inc
index 1810a6e..c52fcda 100644
--- a/plugins/content_types/panels_ajax_tab_container.inc
+++ b/plugins/content_types/panels_ajax_tab_container.inc
@@ -45,7 +45,8 @@ function panels_ajax_tab_container_render($subtype, $conf, $panel_args, &$contex
   }
   else {
     $entity_type = $contexts[0]->type[2];
-    $entity_id = array_shift(entity_extract_ids($entity_type, $contexts[0]->data));
+    $entity_ids = entity_extract_ids($entity_type, $contexts[0]->data);
+    $entity_id = array_shift($entity_ids);
     $context_string = $entity_type . ':' . $entity_id;
   }
 
@@ -66,7 +67,8 @@ function panels_ajax_tab_container_render($subtype, $conf, $panel_args, &$contex
   $content = '<div class="panels-ajax-tab-loading" style ="display:none">' . theme('image', $loading_img) . '</div>';
   $preloaded = '';
   if ($tabs) {
-    $preloaded = reset(array_keys($tabs));
+    $tab_keys = array_keys($tabs);
+    $preloaded = reset($tab_keys);
     if ($clean_url && isset($_GET['panels_ajax_tab_tab'])) {
       if ($tabs[$_GET['panels_ajax_tab_tab']]) {
         $preloaded = $_GET['panels_ajax_tab_tab'];
