diff --git a/embed_widgets.info b/embed_widgets.info
index 53da148..977f54b 100644
--- a/embed_widgets.info
+++ b/embed_widgets.info
@@ -1,7 +1,20 @@
 name =  Embed Widgets
 description = Embed content from your site as widgets.
-core = 6.x
+core = 7.x
 package = "Embed Widgets"
-php = 5.0
 
-dependencies[] = url_alter
\ No newline at end of file
+files[] = includes/base/embed_widget.inc
+files[] = includes/base/widget_source.inc
+files[] = includes/base/widget_platform.inc
+files[] = includes/base/widget_format.inc
+files[] = includes/format/flash.inc
+files[] = includes/format/iframe/iframe.inc
+files[] = includes/platform/html.inc
+files[] = includes/platform/googlegadget.inc
+files[] = includes/widgets/embed_widget_view.inc
+files[] = includes/widgets/embed_widget_page.inc
+files[] = includes/widgets/embed_widget_node.inc
+files[] = includes/widgets/embed_widget_callback.inc
+files[] = includes/widgets/embed_widget_block.inc
+files[] = tests/embed_widget.test
+files[] = tests/embed_widgets.test
diff --git a/embed_widgets.install b/embed_widgets.install
index 898390f..30054d4 100644
--- a/embed_widgets.install
+++ b/embed_widgets.install
@@ -1,22 +1,14 @@
 <?php
 
 /**
- * @file embed_widgets.install
+ * @file
  *
  * Contains install and update functions for Embed Widgets.
  */
 
 /**
- * Implementation of hook_install().
+ * Implements hook_schema().
  */
-function embed_widgets_install() {
-  // Create tables.
-  drupal_install_schema('embed_widgets');
-}
-
-/**
-* Implementation of hook_schema().
-*/
 function embed_widgets_schema() {
   $schema = embed_widgets_table_embed_widgets();
   return $schema;
@@ -95,15 +87,14 @@ function embed_widgets_table_embed_widgets() {
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function embed_widgets_uninstall() {
-  drupal_uninstall_schema('embed_widgets');
   db_query("DELETE FROM {variable} WHERE name LIKE 'embed_widgets%'");
 }
 
 /**
- * Implementation of hook_update_N().
+ * Implements hook_update_N().
  */
 function embed_widgets_update_6200() {
   $ret = array();
@@ -120,7 +111,7 @@ function embed_widgets_update_6200() {
       db_drop_table($ret, $table);
     }
   }
-  
+
   $schema = embed_widgets_table_embed_widgets();
   db_create_table($ret, 'embed_widgets', $schema['embed_widgets']);
   return $ret;
diff --git a/embed_widgets.module b/embed_widgets.module
index dd169ce..eabfba8 100644
--- a/embed_widgets.module
+++ b/embed_widgets.module
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * @file embed_widgets.module
+ * @file
  * Enables the distribution of widgets that can be embedded in other (including non-Drupal) sites.
  *
  * Provides hooks for modules to create new widget types.
@@ -9,13 +9,13 @@
  */
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function embed_widgets_menu() {
   $items = array();
-  
+
   $items['embed-widgets/%embed_widgets/embed'] = array(
-    'description' => 'The embedded file.',
+    'description' => 'The embedded file. ',
     'page callback' => 'embed_widgets_embed_file',
     'page arguments' => array(1),
     'access callback' => 'user_access',
@@ -23,7 +23,7 @@ function embed_widgets_menu() {
     'type' => MENU_CALLBACK,
   );
   $items['embed-widgets/%embed_widgets/content'] = array(
-    'description' => 'The embedded widget content.',
+    'description' => 'The embedded widget content. ',
     'page callback' => 'embed_widgets_render',
     'page arguments' => array(1),
     'access callback' => 'user_access',
@@ -31,7 +31,7 @@ function embed_widgets_menu() {
     'type' => MENU_CALLBACK,
   );
   $items['embed-widgets/%embed_widgets/platform'] = array(
-    'description' => 'A platform-specific file.',
+    'description' => 'A platform-specific file. ',
     'page callback' => 'embed_widgets_platform_file',
     'page arguments' => array(1),
     'access callback' => 'user_access',
@@ -40,55 +40,61 @@ function embed_widgets_menu() {
   );
   $items['embed-widgets/%embed_widgets/share'] = array(
     'title' => 'Share this widget!',
-    'description' => 'Share this widget across in various formats.',
+    'description' => 'Share this widget across in various formats. ',
     'page callback' => 'embed_widgets_share',
     'page arguments' => array(1),
     'access callback' => 'user_access',
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
-  
+
   return $items;
 }
 
 /**
- * Implementation of hook_boot().
+ * Implements hook_boot().
  */
 function embed_widgets_boot() {
-  global $widgets_mode;
-  $widgets_mode = isset($_REQUEST['widgets_mode']) ? $_REQUEST['widgets_mode'] : NULL;
+  global $_embed_widgets_mode;
+  $_embed_widgets_mode = isset($_REQUEST['widgets_mode']) ? $_REQUEST['widgets_mode'] : NULL;
 
   spl_autoload_register('embed_widgets_autoload');
 }
 
 /**
- * Implementation of hook_init().
+ * Implements hook_init().
  */
 function embed_widgets_init() {
-  global $widgets_mode;
+  global $_embed_widgets_mode;
 
-  if ($widgets_mode) {
+  if ($_embed_widgets_mode) {
     module_invoke('admin_menu', 'suppress');
-    $widget = embed_widgets_load($widgets_mode);
+    $widget = embed_widgets_load($_embed_widgets_mode);
     $widget->add_css();
   }
 }
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function embed_widgets_theme() {
   $ret = array(
     'widget' => array(
       'template' => 'widget',
-      'arguments' => array('content' => NULL, 'show_blocks' => TRUE, 'show_messages' => TRUE),
+      'variables' => array('content' => NULL, 'show_blocks' => TRUE, 'show_messages' => TRUE),
       'path' => 'sites/all/modules/embed_widgets'
     ),
     'embed_widgets_share_code' => array(
-      'arguments' => array('code' => NULL, 'widget' => NULL, 'platform' => NULL)
+      'variables' => array('code' => NULL, 'widget' => NULL, 'platform' => NULL)
+    ),
+    'embed_widgets_share_link' => array(
+      'variables' => array('element' => NULL),
+    ),
+    'embed_widgets_block_content' => array(
+      'variables' => array(),
     ),
   );
-  
+
   $themes = embed_widgets_component_invoke_all(NULL, 'theme');
   foreach ($themes as $name => $theme_array) {
     if (isset($theme_array)) {
@@ -105,25 +111,43 @@ function embed_widgets_theme() {
  * @param $widget
  * @param $platform
  */
-function theme_embed_widgets_share_code($code, $widget, $platform) {
+function theme_embed_widgets_share_code(&$variables) {
   $form['widget_code'] = array(
     '#type' => 'textfield',
     '#input' => TRUE,
     '#title' => t('Copy') . ' &amp; ' . t('Paste'),
     '#size' => 25,
-    '#value' => $code,
+    '#value' => $variables['code'],
     '#maxlength' => 900,
     '#attributes' => array('onClick' => "javascript:this.focus(); this.select()"),
-    '#description' => $platform['description'],
+    '#description' => $variables['platform']['description'],
   );
   return drupal_render($form['widget_code']);
 }
 
 /**
- * Implementation of hook_theme_registry_alter().
+ * Theme embed share widget link.
+ * @param $widget
+ */
+function theme_embed_widgets_share_link(&$variables) {
+  $widget = $variables['element']['#widget'];
+  if (arg(2) == 'share') {
+    $title = isset($variables['element']['#title']) ? $variables['element']['#title'] : variable_get('embed_widgets_back_text', t("Back"));
+    $output = l($title, $widget->get_content_url(), array('attributes' => array('class' => 'back')));
+  }
+  else {
+    $title = isset($variables['element']['#title']) ? $variables['element']['#title'] : variable_get('embed_widgets_share_text', t("Share this widget!"));
+    $output = l($title, $widget->get_share_url(), array('attributes' => array('class' => 'share')));
+  }
+  return '<div id="embed-widgets-share-link">' . $output . '</div>';
+}
+
+/**
+ * Implements hook_theme_registry_alter().
  */
 function embed_widgets_theme_registry_alter(&$theme_registry) {
   $path = drupal_get_path('module', 'embed_widgets');
+  $theme_registry['page']['theme paths'] = isset($theme_registry['page']['theme paths']) ? $theme_registry['page']['theme paths'] : array();
   if (!in_array($path, $theme_registry['page']['theme paths'])) {
     array_unshift($theme_registry['page']['theme paths'], $path);
   }
@@ -140,10 +164,10 @@ function embed_widgets_autoload($class_name) {
 
   if (!class_exists($class_name, FALSE)) {
     if (!count($files)) {
-      $files = drupal_system_listing(".inc", drupal_get_path('module', 'embed_widgets') ."/includes", 'name', 0);
+      $files = drupal_system_listing("/\.inc$/", drupal_get_path('module', 'embed_widgets') ."/includes", 'name', 0);
     }
     if (isset($files[$class_name])) {
-      require './' . $files[$class_name]->filename;
+      require DRUPAL_ROOT . '/' . $files[$class_name]->uri;
     }
   }
 }
@@ -160,19 +184,22 @@ function embed_widgets_autoload($class_name) {
  * @return
  *   An array of file objects optionally matching $provider.
  */
-function embed_widgets_system_list($component = './', $class = NULL, $load = TRUE) {
+function embed_widgets_system_list($component = ' ./', $class = '', $load = TRUE) {
+  if ($class) {
+    $class = '\.' . $class;
+  }
   if ($component == 'format') {
-    $files = drupal_system_listing("$class\.inc", drupal_get_path('module', 'embed_widgets') ."/includes/$component/$class", 'name', 0);
+    $files = drupal_system_listing("/$class\.inc$/", drupal_get_path('module', 'embed_widgets') . "/includes/$component/$class", 'name', 0);
   }
   else {
-    $files = drupal_system_listing("$class\.inc", drupal_get_path('module', 'embed_widgets') ."/includes/$component", 'name', 0);
+    $files = drupal_system_listing("/$class\.inc$/", drupal_get_path('module', 'embed_widgets') . "/includes/$component", 'name', 0);
   }
 
   ksort($files);
 
   if ($load) {
     foreach ($files as $file) {
-      include_once('./'. $file->filename);
+      include_once(DRUPAL_ROOT . '/' . $file->uri);
     }
   }
   return $files;
@@ -182,14 +209,14 @@ function embed_widgets_system_list($component = './', $class = NULL, $load = TRU
  * Determine whether an include implements a hook, cf. module_hook.
  *
  * @param $provider
- *   The name of the provider file (without the .inc extension), such as 'youtube' or 'google'.
+ *   The name of the provider file (without the .inc extension), such as 'youtube' or 'google' .
  * @param $hook
  *   The name of the hook (e.g. "thumbnail", "settings", etc.).
  * @return
  *   TRUE if the provider is loaded and the hook is implemented.
  */
 function embed_widgets_include_hook($class, $hook) {
-  return function_exists('embed_widgets_'. $class .'_'. $hook);
+  return function_exists('embed_widgets_' . $class . '_' . $hook);
 }
 
 /**
@@ -211,7 +238,7 @@ function embed_widgets_component_invoke() {
   $component = array_shift($args);
   $class = array_shift($args);
   $hook     = array_shift($args);
-  $function = $class .'::'. $hook;
+  $function = $class . '::' . $hook;
   embed_widgets_system_list($component, $class);
   return method_exists($class, $hook) ? call_user_func_array($function, $args) : NULL;
 }
@@ -237,7 +264,7 @@ function embed_widgets_component_invoke_all() {
   $files = embed_widgets_system_list($component);
   $ret = array();
   foreach ($files as $name => $object) {
-    $function = $name .'::'. $hook;
+    $function = $name . '::' . $hook;
     if (method_exists($name, $hook)) {
       $data = call_user_func_array($function, $args);
       if (!empty($data)) {
@@ -252,7 +279,7 @@ function embed_widgets_component_invoke_all() {
  * Gets information about each class.
  *
  * @param $refresh
- *  If true, the cache will be rebuilt.
+ *  If TRUE, the cache will be rebuilt.
  * @return
  *   An associative array of information provided by the "info" hook.
  */
@@ -263,11 +290,13 @@ function embed_widgets_get_info($refresh = NULL) {
 
   static $info = array();
 
-  if (empty($info) || isset($refresh)  || !is_array($info)) {
-    $cache = cache_get('embed_widgets_info_'. $id);
-    $info = $cache->data;
+  if (empty($info) || isset($refresh)) {
+    $cache = cache_get('embed_widgets_info_' . $id);
+    if ($cache !== FALSE) {
+      $info = $cache->data;
+    }
   }
-  if (empty($info) || isset($refresh)  || !is_array($info)) {
+  if (empty($info) || isset($refresh)) {
     $info = array();
     $info['format'] = embed_widgets_component_invoke_all('format', 'info');
     $info['platform'] = embed_widgets_component_invoke_all('platform', 'info');
@@ -285,31 +314,31 @@ function embed_widgets_get_info($refresh = NULL) {
       }
     }
     $info['module_widgets'] = embed_widgets_get_widgets();
-    cache_set('embed_widgets_info_'. $id, $info, 'cache', CACHE_TEMPORARY);
+    cache_set('embed_widgets_info_' . $id, $info, 'cache', CACHE_TEMPORARY);
   }
   return $info;
 }
 
 /**
-* Return widgets declared programmatically by modules.
-*/
+ * Return widgets declared programmatically by modules.
+ */
 function embed_widgets_get_widgets() {
   $module_widgets = array();
-  
+
   $modules = module_implements('embed_widgets');
   foreach ($modules as $module) {
-    $widgets = call_user_func($module .'_embed_widgets');
+    $widgets = call_user_func($module . '_embed_widgets');
     if (!empty($widgets)) {
       $module_widgets[$module] = $widgets;
     }
   }
-  
+
   return $module_widgets;
 }
 
 /**
-* Return information about a certain widget declared by a specified module.
-*/
+ * Return information about a certain widget declared by a specified module.
+ */
 function embed_widgets_module_widget($module, $delta) {
   $info = embed_widgets_get_info();
   return $info['module_widgets'][$module][$delta];
@@ -368,9 +397,11 @@ function embed_widgets_new($type = NULL, $id = NULL, $delta = NULL, $platform =
 function embed_widgets_load($type, $id = NULL, $delta = NULL, $platform = 'html', $format = 'iframe') {
   if (isset($id)) {
     $class = 'embed_widget_' . $type;
+    $cache_id = NULL;
   }
   elseif (is_string($type)) {
     $decoded = embed_widget::decode($type);
+    $class = $cache_id = NULL;
     if (!empty($decoded)) {
       $type = $decoded['type'];
       $id = $decoded['id'];
@@ -391,30 +422,30 @@ function embed_widgets_load($type, $id = NULL, $delta = NULL, $platform = 'html'
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implements hook_form_alter().
  */
-function embed_widgets_form_alter(&$form, $form_state, $form_id) {
-  global $widgets_mode;
-  if ($widgets_mode) {
-    //$form['#submit'][] = 'embed_widgets_form_override_submit';
-    //$form['#validate'][] = 'embed_widgets_form_override_submit';
-    
+function embed_widgets_form_alter(&$form, &$form_state, $form_id) {
+  global $_embed_widgets_mode;
+  if ($_embed_widgets_mode) {
+//     $form['#submit'][] = 'embed_widgets_form_override_submit';
+//     $form['#validate'][] = 'embed_widgets_form_override_submit';
+
 //    $buttons = embed_widgets_array_search_recursive('submit', $form);
 //    foreach($buttons as $key => $value) {
 //      if (is_array($value)) {
 //        $form[$key] = embed_widgets_array_insert($form[$key], $buttons[$key]);
 //      }
 //    }
-    /*$buttons = embed_widgets_array_search_recursive('validate', $form);
-    foreach($buttons as $key => $value) {
-      if (is_array($value)) {
-        $form[$key] = embed_widgets_array_insert($form[$key], $buttons[$key]);
-      }
-    }*/
-    
+//     $buttons = embed_widgets_array_search_recursive('validate', $form);
+//     foreach($buttons as $key => $value) {
+//       if (is_array($value)) {
+//         $form[$key] = embed_widgets_array_insert($form[$key], $buttons[$key]);
+//       }
+//     }
+
     $form['widgets_mode'] = array(
       '#type' => 'hidden',
-      '#value' => $widgets_mode,
+      '#value' => $_embed_widgets_mode,
     );
   }
 }
@@ -442,7 +473,7 @@ function embed_widgets_array_insert($arr, $ins) {
 }
 
 /**
- * Hook implementation of custom_url_rewrite_outbound().
+ * Implements hook_url_outbound_alter().
  *
  * Alter links generated by Drupal.
  *
@@ -465,105 +496,100 @@ function embed_widgets_array_insert($arr, $ins) {
  *   The unaliased Drupal path that is being linked.
  */
 function embed_widgets_url_outbound_alter(&$path, &$options, $original_path) {
-  global $widgets_mode;
-
-  if (!empty($widgets_mode) && empty($options['external'])) {
+  global $_embed_widgets_mode;
 
-    $behavior = variable_get('embed_widgets_link_behavior', 0);
-    $pages = variable_get('embed_widgets_link_pages', "node/*\n");
+  if (!empty($_embed_widgets_mode)) {
+    if (empty($options['external'])) {
+      $behavior = variable_get('embed_widgets_link_behavior', 0);
+      $pages = variable_get('embed_widgets_link_pages', "node/*\n");
 
-    $match = (drupal_match_path($path, $pages) || drupal_match_path($original_path, $pages));
+      $match = (drupal_match_path($path, $pages) || drupal_match_path($original_path, $pages));
 
-    if (!($behavior xor $match)) {
-      if (empty($options['query'])) {
-        $options['query'] = 'widgets_mode=' . $widgets_mode;
-      }
-      elseif (is_array($options['query'])) {
-        $options['query']['widgets_mode'] = $widgets_mode;
-      }
-      else {
-        $options['query'] .= '&widgets_mode=' . $widgets_mode;
+      if (!($behavior xor $match)) {
+        $options['query']['widgets_mode'] = $_embed_widgets_mode;
       }
     }
+    if (!isset($options['query']['widgets_mode']) && !isset($options['attributes']['target'])) {
+      $options['attributes']['target'] = '_blank';
+    }
   }
 }
 
 /**
- * Implementation of hook_preprocess_page().
+ * Implements hook_preprocess_page().
  */
 function embed_widgets_preprocess_page(&$variables) {
-  global $widgets_mode;
+  global $_embed_widgets_mode;
   global $theme_key;
-  
-  // Add template suggestions if in widgets mode.
-  if (isset($widgets_mode)) {
-    $variables['body_classes'] = str_replace(" sidebar-left", "", $variables['body_classes']);
-    $variables['body_classes'] = str_replace(" sidebar-right", "", $variables['body_classes']);
-    $variables['body_classes'] = str_replace(" sidebar-left", "", $variables['body_classes']);
-    $variables['body_classes'] .= ' embed-widget';
-
-    $widget = embed_widgets_load($widgets_mode);
-    
-    foreach ($variables['template_files'] as $template) {
+
+  if (isset($_embed_widgets_mode)) {
+    // Load the widget.
+    $widget = embed_widgets_load($_embed_widgets_mode);
+
+    // Add template suggestions if in widgets mode.
+    foreach ($variables['theme_hook_suggestions'] as $template) {
       if (substr_compare($template, "page", 0, 5)) {
         $template = substr($template, 4);
       }
-      $suggestions[] = 'widget-' . $widget->format . $template;
+      $suggestions[] = 'widget__' . $widget->format . $template;
     }
     $variables['width'] = $widget->get_variable('width');
     $variables['height'] = $widget->get_variable('height');
-    
-    $variables['template_files'][] = 'widget-' . $widget->format;
-    
+
+    $variables['theme_hook_suggestions'][] = 'widget__' . $widget->format;
+
     if (!empty($suggestions)) {
       foreach ($suggestions as $template) {
-        $variables['template_files'][] = $template;
+        $variables['theme_hook_suggestions'][] = $template;
       }
     }
-    embed_widgets_alter_links($variables['content']);
-    if (!empty($variables['tabs'])) {
-      embed_widgets_alter_links($variables['tabs']);
-    }
-    $regions = system_region_list($theme_key);
-    
-    foreach ($regions as $region => $name) {
-      if (!empty($variables[$region])) {
-        embed_widgets_alter_links($variables[$region]);
+
+    // Add the share widget variable.
+    $variables['page']['content']['embed_widgets_share'] = array(
+      '#theme' => 'embed_widgets_share_link',
+      '#element' => array('#widget' => $widget),
+    );
+
+    // Blank all regions but content.
+    foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
+      if (!in_array($region_key, variable_get('embed_widgets_page_regions_allowed', array('content', 'page_top', 'page_bottom')))) {
+        $variables['page'][$region_key] = array();
       }
     }
-    
-    $variables['share_widget'] = l(variable_get('embed_widgets_share_text', t("Share this widget!")), $widget->get_share_url());
-    if (arg(2) == 'share') {
-      $variables['back_to_widget'] = l(t("Back"), $widget->get_content_url());
-      $variables['widget_url'] = $widget->get_content_url();
-    }
+
+    // Remove other elements that we don't want to display.
+    $variables['main_menu'] = $variables['secondary_menu'] = $variables['action_links'] = array();
+    drupal_set_breadcrumb(array());
+    $variables['hide_site_name'] = $variables['hide_site_slogan'] = TRUE;
+    $variables['site_name'] = $variables['site_slogan'] = $variables['logo'] = NULL;
+
   }
 }
 
 /**
- * Implementation of hook_preproccess_node().
+ * Implements hook_preproccess_node().
  */
 function embed_widgets_preprocess_node(&$variables) {
-  global $widgets_mode;
-  
-  if (isset($widgets_mode)) {
-    foreach ($variables['template_files'] as $template) {
-      $variables['template_files'][] = 'widget-' . $template;
+  global $_embed_widgets_mode;
+
+  if (isset($_embed_widgets_mode)) {
+    foreach ($variables['theme_hook_suggestions'] as $template) {
+      $variables['theme_hook_suggestions'][] = 'widget__' . $template;
     }
   }
 }
 
 /**
- * Implementation of hook_preproccess_block().
+ * Implements hook_preproccess_block().
  */
 function embed_widgets_preprocess_block(&$variables) {
-  global $widgets_mode;
-  
-  if (!isset($widgets_mode) && $variables['block']->module != 'embed_widgets') {
+  global $_embed_widgets_mode;
+
+  if (!isset($_embed_widgets_mode) && $variables['block']->module != 'embed_widgets') {
     $widget = embed_widgets_new('block', $variables['block']->module, $variables['block']->delta);
     if (!empty($widget->status)) {
       $variables['share_widget_link'] = l(variable_get('embed_widgets_share_text', t("Share this widget!")), $widget->get_share_url());
-      
+
       if (variable_get('embed_widgets_block_append_link', FALSE)) {
         $variables['block']->content .= '<div class="widgets-share-link">' . $variables['share_widget_link'] . '</div>';
       }
@@ -587,23 +613,23 @@ function embed_widgets_alter_links(&$string) {
 //  $domain = preg_quote($domain, '/');
 //  $behavior = variable_get('embed_widgets_link_behavior', 0);
 //  $pages = variable_get('embed_widgets_link_pages', "node/*\n");
-  
+
   $dom = new DOMDocument();
   $dom->loadHTML(mb_convert_encoding($string, 'HTML-ENTITIES', "UTF-8"));
-  
+
   // Get all links
   $a_tags = $dom->getElementsByTagName('a');
-  
+
   // Loop through links
   foreach ($a_tags as $tag) {
     $href = trim($tag->getAttribute('href'), ' /');
     $target = trim($tag->getAttribute('target'));
-    
+
     if ($target != "_blank" && strpos($href, 'widgets_mode=') === FALSE) {
         $tag->setAttribute('target', "_blank");
       }
-   }
-          
+  }
+
   $string = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML()));
   return $string;
 }
@@ -621,47 +647,47 @@ function embed_widgets_alter_links(&$string) {
  */
 function embed_widgets_array_walk_recursive(&$input, $funcname) {
   static $depth = -1;
-   if (!is_callable($funcname)) {
-       return false;
-   }
+  if (!is_callable($funcname)) {
+      return FALSE;
+  }
 
-   if (!is_array($input)) {
-       return false;
-   }
+  if (!is_array($input)) {
+      return FALSE;
+  }
 
-   $depth++;
+  $depth++;
 
-   foreach (array_keys($input) AS $keyIdx => $key) {
-        $saved_value = $input[$key];
-        $saved_key = $key;
-        call_user_func_array($funcname, array(&$input[$saved_key], &$key));
+  foreach (array_keys($input) AS $keyIdx => $key) {
+      $saved_value = $input[$key];
+      $saved_key = $key;
+      call_user_func_array($funcname, array(&$input[$saved_key], &$key));
 
-        if ($input[$saved_key] !== $saved_value || $saved_key !== $key) {
-            $saved_value = $input[$saved_key];
+      if ($input[$saved_key] !== $saved_value || $saved_key !== $key) {
+          $saved_value = $input[$saved_key];
 
-            unset($input[$saved_key]);
-            $input[$key] = $saved_value;
-        }
-       if (is_array($input[$key])) {
-            if (!embed_widgets_array_walk_recursive($input[$key], $funcname)) return false;
-            $depth--;
-       }
-   }
-   return true;
+          unset($input[$saved_key]);
+          $input[$key] = $saved_value;
+      }
+      if (is_array($input[$key])) {
+          if (!embed_widgets_array_walk_recursive($input[$key], $funcname)) return FALSE;
+          $depth--;
+      }
+  }
+  return TRUE;
 }
 
 /**
  * FAPI submit handler to force pages to stay in 'widget mode' after form submission.
  */
 function embed_widgets_form_override_submit($form, &$form_state) {
-  global $widgets_mode;
+  global $_embed_widgets_mode;
   $options = array();
   if ($form['#id'] == 'node-form' && !isset($form_state['redirect'])) {
-    $form_state['redirect'] = 'node/'. $node->nid;
+    $form_state['redirect'] = 'node/' . $node->nid;
   }
   if (isset($form_state['redirect'])) {
     if (is_array($form_state['redirect'])) {
-      $form_state['redirect'][1]['widgets_mode'] = $widgets_mode;
+      $form_state['redirect'][1]['widgets_mode'] = $_embed_widgets_mode;
       $path = $form_state['redirect'][0];
       if (isset($form_state['redirect'][1]) && is_array($form_state['redirect'][1])) {
         $options = $form_state['redirect'][1];
@@ -671,16 +697,16 @@ function embed_widgets_form_override_submit($form, &$form_state) {
       $path = $form_state['redirect'];
       $form_state['redirect'] = array();
       $form_state['redirect'][0] = $path;
-      $form_state['redirect'][1]['widgets_mode'] = $widgets_mode;
+      $form_state['redirect'][1]['widgets_mode'] = $_embed_widgets_mode;
     }
   }
   elseif (isset($_REQUEST['destination'])) {
-    $_REQUEST['destination'] .= '?widgets_mode=' . $widgets_mode;
+    $_REQUEST['destination'] .= '?widgets_mode=' . $_embed_widgets_mode;
   }
   else {
     $item = menu_get_item();
     $path = $item['href'];
-    $_REQUEST['destination'] = $item['href'] . '?widgets_mode=' . $widgets_mode;
+    $_REQUEST['destination'] = $item['href'] . '?widgets_mode=' . $_embed_widgets_mode;
   }
 }
 
@@ -694,17 +720,17 @@ function embed_widgets_form_override_submit($form, &$form_state) {
  * @return
  *   An a array of elements that were found and modified.
  */
-function embed_widgets_array_search_recursive($needle, $haystack){
-  $path=array();
-  foreach($haystack as $id => $val) {
-    if($id == '#type' && $val === $needle) {
-     $path[$id]=$val;
-     $path['#' . $needle]['widgets'] = 'embed_widgets_form_override_submit';
+function embed_widgets_array_search_recursive($needle, $haystack) {
+  $path = array();
+  foreach ($haystack as $id => $val) {
+    if ($id == '#type' && $val === $needle) {
+      $path[$id] = $val;
+      $path['#' . $needle]['widgets'] = 'embed_widgets_form_override_submit';
     }
-    else if(is_array($val)){
-     $found=embed_widgets_array_search_recursive($needle, $val);
-      if(count($found)>0){
-          $path[$id]=$found;
+    elseif (is_array($val)) {
+      $found = embed_widgets_array_search_recursive($needle, $val);
+      if (count($found)>0) {
+          $path[$id] = $found;
       }
     }
   }
@@ -720,18 +746,18 @@ function embed_widgets_array_search_recursive($needle, $haystack){
  *   The HTML content to be displayed.
  */
 function embed_widgets_render($widget) {
-  global $widgets_mode;
+  global $_embed_widgets_mode;
   module_invoke('admin_menu', 'suppress');
-  
-  $widgets_mode = $widget->encode();
-  drupal_add_js(array(widgetID => $widgets_mode), 'setting');
+
+  $_embed_widgets_mode = $widget->encode();
+  drupal_add_js(array('widgetID' => $_embed_widgets_mode), 'setting');
   $base = drupal_get_path('module', 'embed_widgets');
-  
+
   $widget->add_css();
 
   $content = $widget->build();
   drupal_set_title($widget->title);
-  
+
   return $content['content'];
 }
 
@@ -777,19 +803,19 @@ function embed_widgets_share(embed_widget $widget) {
   $links = array();
 
   $platforms = variable_get('embed_widgets_platforms', array('html' => 'html'));
-  
+
   if (empty($platforms)) {
     $platforms = array_keys($info['platform']);
   }
 
-  foreach($info['platform'] as $id => $platform) {
+  foreach ($info['platform'] as $id => $platform) {
     if (!empty($platforms[$id])) {
       $widget->platform = $id;
 
       if ($platform['share_method'] == 'code') {
         $code = $widget->get_code();
 
-        $content .= theme('embed_widgets_share_code', $code, $widget, $platform);
+        $content .= theme('embed_widgets_share_code', array('code' => $code, 'widget' => $widget, 'platform' => $platform));
       }
       elseif ($platform['share_method'] == 'link') {
         $links[] = $widget->get_link();
@@ -800,69 +826,50 @@ function embed_widgets_share(embed_widget $widget) {
   if (!empty($links)) {
     $content .= theme('item_list', $links, NULL, 'ul', array('class' => 'widget-links'));
   }
-  
+
   return $content;
 }
 
 /**
- * Implementation of hook_block().
- */
-function embed_widgets_block($op = 'list', $delta = 0, $edit = array()) {
-  switch ($op) {
-    case 'list':
-      // If $op is "list", we just need to return a list of block descriptions.
-      // This is used to provide a list of possible blocks to the administrator,
-      // end users will not see these descriptions.
-      $blocks[0] = array(
-        'info'       => t('Widgets embed code'),
-      );
-      return $blocks;
-    case 'configure':
-      $form = array();
-      if ($delta == 0) {
-//        $form['block_example_string'] = array(
-//          '#type' => 'textfield',
-//          '#title' => t('Block contents'),
-//          '#size' => 60,
-//          '#description' => t('This string will appear in the example block.'),
-//          '#default_value' => variable_get('block_example_string',  t('Some example content.')),
-//        );
-      }
-      return $form;
-    case 'save':
-      if ($delta == 0) {
-        // save the string to the database.
-        //variable_set('block_example_string', $edit['block_example_string']);
-      }
-      return;
-    case 'view': default:
-      switch ($delta) {
-        case 0:
-          $block['subject'] = t('Embed this content');
-          $block['content'] = embed_widgets_block_contents();
-          break;
-      }
-      return $block;
+ * Implements hook_block_info().
+ */
+function embed_widgets_block_info() {
+  $blocks[0] = array(
+    'info'       => t('Widgets embed code'),
+  );
+  return $blocks;
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function embed_widgets_block_view($delta = 0) {
+  switch ($delta) {
+    case 0:
+      $block['subject'] = t('Embed this content');
+      $block['content'] = theme('embed_widgets_block_content');
+      break;
   }
+  return $block;
 }
 
 /**
  * Returns the contents of the widget embed code block.
  */
-function embed_widgets_block_contents() {
+function theme_embed_widgets_block_content() {
   $item = menu_get_item();
-  
+
   $enabled_types = variable_get('embed_widgets_widget_types', array_fill_keys(array('node', 'block', 'view'), 1));
   $info = embed_widgets_get_info();
   $info = $info['sources'];
-  
+
   $page = $info['embed_widget_page'];
   unset($info['embed_widget_page']);  // TODO: This one must be last. Implement weights?
   $info['embed_widget_page'] = $page;
 
-  foreach($info as $class => $widget_type) {
+  foreach ($info as $class => $widget_type) {
     if (!empty($enabled_types[$widget_type['name']])) {
-      $method = $class .'::'. 'path_load';
+      $method = $class . '::' . 'path_load';
       $widget = call_user_func($method);
       if (is_object($widget)) {
         return embed_widgets_share($widget);
@@ -873,15 +880,15 @@ function embed_widgets_block_contents() {
     }
   }
   return NULL;
-  
+
 }
 
 /**
- * Implementation of hook_views_api().
+ * Implements hook_views_api().
  */
 function embed_widgets_views_api() {
   return array(
     'api' => 2,
-    'path' => drupal_get_path('module', 'embed_widgets') .'/views',
+    'path' => drupal_get_path('module', 'embed_widgets') . '/views',
   );
 }
diff --git a/embed_widgets_ui/embed_widgets_ui.info b/embed_widgets_ui/embed_widgets_ui.info
index 3e33ec5..d8d83cf 100644
--- a/embed_widgets_ui/embed_widgets_ui.info
+++ b/embed_widgets_ui/embed_widgets_ui.info
@@ -1,7 +1,7 @@
 name =  Embed Widgets UI
 description = UI for creating and managing widgets.
 dependencies[] = embed_widgets
-core = 6.x
+core = 7.x
 package = "Embed Widgets"
 
 
diff --git a/embed_widgets_ui/embed_widgets_ui.js b/embed_widgets_ui/embed_widgets_ui.js
index 60b43b0..e1c8350 100644
--- a/embed_widgets_ui/embed_widgets_ui.js
+++ b/embed_widgets_ui/embed_widgets_ui.js
@@ -1,28 +1,32 @@
-Drupal.behaviors.embedWidgetsBehavior = function (context) {
-  $("#edit-embed-widgets-override").ready(embed_widgets_override_load);
-  $("#edit-embed-widgets-override").change(embed_widgets_override_values);
+(function ($) {
+  Drupal.behaviors.embedWidgetsBehavior = {
+    attach: function (context) {
+      $("#edit-embed-widgets-override").ready(embed_widgets_override_load);
+      $("#edit-embed-widgets-override").change(embed_widgets_override_values);
+    }
+  };
 
-}; 
+  embed_widgets_override_load = function () {
+    var checked = $("#edit-embed-widgets-override:checked").val();
 
-embed_widgets_override_load = function () {
-  var checked = $("#edit-embed-widgets-override:checked").val();
+    if(checked == 1){
+      $('#embed-widgets-hide-wrapper').css("display","block");
+    }
+    else {
+      $('#embed-widgets-hide-wrapper').css("display","none");
+    }
+  };
 
-  if(checked == 1){
-    $('#embed-widgets-hide-wrapper').css("display","block");
-  }
-  else {
-    $('#embed-widgets-hide-wrapper').css("display","none");
-  }
-}
 
+  embed_widgets_override_values = function () {
+    var checked = $("#edit-embed-widgets-override:checked").val();
 
-embed_widgets_override_values = function () {
-  var checked = $("#edit-embed-widgets-override:checked").val();
+    if(checked == 1){
+      $('#embed-widgets-hide-wrapper').show('slow');
+    }
+    else {
+      $('#embed-widgets-hide-wrapper').hide('slow');
+    }
+  };
 
-  if(checked == 1){
-    $('#embed-widgets-hide-wrapper').show('slow');
-  }
-  else {
-    $('#embed-widgets-hide-wrapper').hide('slow');
-  }
-}
+})(jQuery);
diff --git a/embed_widgets_ui/embed_widgets_ui.module b/embed_widgets_ui/embed_widgets_ui.module
index cdb2106..49c6a50 100644
--- a/embed_widgets_ui/embed_widgets_ui.module
+++ b/embed_widgets_ui/embed_widgets_ui.module
@@ -2,8 +2,8 @@
 
 function embed_widgets_ui_menu() {
   $items = array();
-  
-  $items['admin/settings/embed-widgets'] = array(
+
+  $items['admin/config/services/embed-widgets'] = array(
     'title' => 'Embed Widgets',
     'description' => 'Configuration for embed widgets',
     'page callback' => 'drupal_get_form',
@@ -11,7 +11,7 @@ function embed_widgets_ui_menu() {
     'access arguments' => array('administer widgets'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/settings/embed-widgets/setup'] = array(
+  $items['admin/config/services/embed-widgets/setup'] = array(
     'title' => 'Setup',
     'description' => 'Configuration for embed widgets',
     'page callback' => 'drupal_get_form',
@@ -20,7 +20,7 @@ function embed_widgets_ui_menu() {
     'weight' => -10,
     'type' => MENU_DEFAULT_LOCAL_TASK,
   );
-  $items['admin/settings/embed-widgets/defaults'] = array(
+  $items['admin/config/services/embed-widgets/defaults'] = array(
     'title' => 'Default Values',
     'description' => 'Set default values for widget.',
     'page callback' => 'drupal_get_form',
@@ -28,7 +28,7 @@ function embed_widgets_ui_menu() {
     'access arguments' => array('administer widgets'),
     'type' => MENU_LOCAL_TASK,
   );
-  $items['admin/settings/embed-widgets/platforms'] = array(
+  $items['admin/config/services/embed-widgets/platforms'] = array(
     'title' => 'Platforms',
     'description' => 'Platform-specific settings.',
     'page callback' => 'drupal_get_form',
@@ -36,12 +36,6 @@ function embed_widgets_ui_menu() {
     'access arguments' => array('administer widgets'),
     'type' => MENU_LOCAL_TASK,
   );
-  
-  $items['embed-widgets/preview'] = array(
-    'page callback' => 'embed_widgets_ui_preview',
-    'access arguments' => array('access content'),
-    'type' => MENU_LOCAL_TASK,
-  );
 
 //  $items['embed-widgets/edit/%embed_widgets'] = array(
 //    'title' => 'Edit Widget',
@@ -57,10 +51,19 @@ function embed_widgets_ui_menu() {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function embed_widgets_ui_perm() {
-  return array('administer widgets', 'override widget default settings');
+function embed_widgets_ui_permission() {
+  return array(
+    'administer widgets' => array(
+      'title' => t('Administer widgets'),
+      'description' => t('Perform administration tasks for the Embed Widgets module.')
+    ),
+    'override widget default settings' => array(
+      'title' => t('Override widget default settings'),
+      'description' => t('Allow the user to override default settings when embedding a widget.'),
+    ),
+  );
 }
 
 //function embed_widgets_ui_edit_form($form_state, embed_widget $widget) {
@@ -105,27 +108,27 @@ function embed_widgets_ui_override_form(&$form, $widget) {
     '#collapsed' => TRUE,
     '#tree' => TRUE,
   );
-  
+
   $form['embed_widgets']['override'] = array(
     '#type' => 'checkbox',
     '#title' => t('Override default values.'),
     '#default_value' => !empty($widget->wid),
   );
-  
+
   $form['embed_widgets']['prefix'] = array(
     '#type' => 'markup',
     '#value' => '<div id="embed-widgets-hide-wrapper">',
   );
 
   $form['embed_widgets']['attributes'] = embed_widget_node::widget_attributes_form($widget);
-  
+
   $form['embed_widgets']['settings'] = embed_widget_node::widget_settings_form($widget->get_settings());
-  
+
   $form['embed_widgets']['suffix'] = array(
     '#type' => 'markup',
     '#value' => '</div>',
-   );
-   
+  );
+
   if (!empty($_REQUEST['has_js'])) {
     $form['embed_widgets']['show_preview'] = array(
       '#type' => 'submit',
@@ -133,8 +136,8 @@ function embed_widgets_ui_override_form(&$form, $widget) {
       '#description' => t("If the amount of boxes above isn't enough, click here to add more choices."),
       '#weight' => 1,
       '#submit' => array('poll_more_choices_submit'), // If no javascript action.
-      '#ahah' => array(
-        'path' => 'embed-widgets/preview',
+      '#ajax' => array(
+        'callback' => 'embed_widgets_ui_preview',
         'wrapper' => 'widget-preview',
         'method' => 'replace',
         'effect' => 'fade',
@@ -142,17 +145,20 @@ function embed_widgets_ui_override_form(&$form, $widget) {
       '#suffix' => '<div id="widget-preview"></div>',
     );
   }
-  
+
   $form['embed_widgets']['widget'] = array(
     '#type' => 'value',
     '#value' => $widget,
   );
-  
+
   $form['#pre_render'][] = 'embed_widgets_ui_override_form_prerender';
 }
 
-function embed_widgets_ui_form_alter(&$form, $form_state) {
-  if ((isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form['form_id']['#value']) && user_access('override widget default settings')) {
+/**
+ * Implements hook_form_node_form_alter().
+ */
+function embed_widgets_ui_form_node_form_alter(&$form, $form_state) {
+  if (user_access('override widget default settings')) {
     $content_types = variable_get('embed_widgets_content_types', array());
     if (!empty($content_types[$form['type']['#value']])) {
       $widget = embed_widgets_load('node', $form['nid']['#value']);
@@ -172,11 +178,11 @@ function embed_widgets_ui_form_block_admin_configure_alter(&$form, $form_state)
   if (user_access('override widget default settings') && !empty($widget_types['block'])) {
     $module = $form['module']['#value'];
     $delta = $form['delta']['#value'];
-  
+
     $widget = embed_widgets_new('block', $module, $delta);
     $widget->title = empty($widget->title) ? $form['block_settings']['title']['#default_value'] : $widget->title;
     embed_widgets_ui_override_form($form, $widget);
-    
+
     $form['#submit']['embed_widgets_block'] = 'embed_widgets_ui_block_edit_submit';
     $form['submit']['#weight'] = 1;
   }
@@ -198,65 +204,72 @@ function embed_widgets_ui_block_edit_submit($form, &$form_state) {
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_node_update().
+ */
+function embed_widgets_ui_node_update($node) {
+  _embed_widgets_node_postsave($node);
+}
+
+/**
+ * Implements hook_node_insert().
+ */
+function embed_widgets_ui_node_insert($node) {
+  _embed_widgets_node_postsave($node);
+}
+
+/**
+ * Implements hook_node_delete().
+ */
+function embed_widgets_ui_node_delete($node) {
+  $widget = embed_widgets_new('node', $node->nid);
+  if (isset($widget->wid)) {
+    $widget->delete();
+  }
+}
+
+/**
+ * Saves the widget override for a node.
  */
-function embed_widgets_ui_nodeapi(&$node, $op = 'view', $teaser, $page) {
-  switch ($op) {
-    case 'load':
-        //$node->widget = embed_widgets_load('node', $node->nid);
-      break;
-    case 'update':
-    case 'insert':
-      if ($node->embed_widgets['override']) {
-        $widget = embed_widgets_new('node', $node->nid);
-        $widget->title = $node->embed_widgets['attributes']['title'];
-        $widget->description = $node->embed_widgets['attributes']['description'];
-        $widget->status = $node->embed_widgets['attributes']['status'];
-        $widget->settings = $node->embed_widgets['settings'];
-        $widget->save();
-        $node->widget_id = $widget->wid;
-      }
-      else  {
-        $widget = embed_widgets_new('node', $node->nid);
-        if (isset($widget->wid)) {
-            $widget->delete();
-        }
-      }
-      
-      break;
-    case 'delete':
-      $widget = embed_widgets_new('node', $node->nid);
-      if (isset($widget->wid)) {
-        $widget->delete();
-      }
-      break;
+function _embed_widgets_node_postsave($node) {
+  if (isset($node->embed_widgets['override']) && $node->embed_widgets['override']) {
+    $widget = embed_widgets_new('node', $node->nid);
+    $widget->title = $node->embed_widgets['attributes']['title'];
+    $widget->description = $node->embed_widgets['attributes']['description'];
+    $widget->status = $node->embed_widgets['attributes']['status'];
+    $widget->settings = $node->embed_widgets['settings'];
+    $widget->save();
+    $node->widget_id = $widget->wid;
+  }
+  else  {
+    $widget = embed_widgets_new('node', $node->nid);
+    if (isset($widget->wid)) {
+      $widget->delete();
+    }
   }
 }
 
 /**
  * Menu callback for AHAH request. Returns HTML to preview a widget.
  */
-function embed_widgets_ui_preview() {
-  $form_build_id = $_REQUEST['form_build_id'];
-  $form_state = array('submitted' => FALSE);
-  $form = form_get_cache($form_build_id, $form_state);
+function embed_widgets_ui_preview($form, $form_state) {
   $widget = $form['embed_widgets']['widget']['#value'];
-  unset($form);
-  
+
   $widget->status = $_REQUEST['embed_widgets']['attributes']['status'];
   $widget->title = $_REQUEST['embed_widgets']['attributes']['title'];
   $widget->description = $_REQUEST['embed_widgets']['attributes']['description'];
   $widget->set_variable('width', $_REQUEST['embed_widgets']['settings']['width']);
   $widget->set_variable('height', $_REQUEST['embed_widgets']['settings']['height']);
-  
+
+  $form_build_id = $_REQUEST['form_build_id'];
   $widget->cache($form_build_id);
-  
+
   $code = $widget->get_code(TRUE);
-  
+
   $output = '<div id="widget-preview">';
   $output .= theme('status_messages') . $code;
   $output .= '</div>';
-  drupal_json(array('status' => TRUE, 'data' => $output));
+
+  return $output;
 }
 
 /**
@@ -269,9 +282,9 @@ function embed_widgets_ui_settings_form() {
 
   $info = embed_widgets_get_info(TRUE);
   $widget_types = variable_get('embed_widgets_widget_types', array('node' => 'node', 'block' => 'block', 'view' => 'view'));
-  
+
   $form = array();
-  
+
   $form['widget_content'] = array(
     '#type' => 'fieldset',
     '#title' => t('Widget Content'),
@@ -279,7 +292,8 @@ function embed_widgets_ui_settings_form() {
     '#collapsed' => FALSE,
     '#description' => t('Configure which elements of your site can be embedded as widgets.'),
   );
-  
+
+  $options = array();
   foreach ($info['sources'] as $key => $source) {
     if ($key != 'embed_widget_callback') {
       $options[$source['name']] = $source['title'];
@@ -298,7 +312,7 @@ function embed_widgets_ui_settings_form() {
     '#description' => t('This text will be used as the text for all "Share this widget" links.'),
     '#default_value' => variable_get('embed_widgets_share_text', t("Share this widget!")),
   );
-  
+
   $form['widget_behavior'] = array(
     '#type' => 'fieldset',
     '#title' => t('Widget Behavior'),
@@ -308,7 +322,7 @@ function embed_widgets_ui_settings_form() {
   );
   $options = array(t('Open only links to the listed pages in a new window.'), t('Open every link in a new window except links to the listed pages.'));
   $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
-  
+
   $form['widget_behavior']['embed_widgets_link_behavior'] = array(
     '#type' => 'radios',
     '#title' => t('Widget link behavior'),
@@ -321,14 +335,14 @@ function embed_widgets_ui_settings_form() {
     '#default_value' => variable_get('embed_widgets_link_pages', "node/*\n"),
     '#description' => $description,
   );
-  
+
   foreach ($info['sources'] as $key => $source) {
-    if (!empty($widget_types[$source['name']]) && method_exists($key, admin_settings_form)) {
+    if (!empty($widget_types[$source['name']]) && method_exists($key, 'admin_settings_form')) {
       $form = $form + call_user_func($key . '::admin_settings_form');
     }
   }
   $form = system_settings_form($form);
-  
+
   $form['#submit'][] = 'embed_widgets_ui_settings_form_submit';
   return $form;
 }
@@ -344,7 +358,7 @@ function embed_widgets_ui_settings_form_submit($form, &$form_state) {
  */
 function embed_widgets_ui_platform_settings_form() {
   $info = embed_widgets_get_info($refresh = FALSE);
-    
+
   $form = array();
 
   foreach ($info['platform'] as $key => $platform) {
@@ -357,11 +371,11 @@ function embed_widgets_ui_platform_settings_form() {
     '#options' => $options,
     '#default_value' => variable_get('embed_widgets_platforms', array('html' => 'html')),
   );
-  
+
   foreach ($info['platform'] as $key => $source) {
     $form = $form + call_user_func($key . '::' . 'settings_form');
   }
-  
+
   $form = system_settings_form($form);
   return $form;
 }
@@ -381,7 +395,7 @@ function embed_widgets_ui_default_settings_form() {
     '#description' => t('This form allows you to configure default settings for newly created widget.'),
   );
   $form['widget']['settings'] = embed_widget::widget_settings_form();
-  
+
   $form['widget_content'] = array(
     '#type' => 'fieldset',
     '#title' => t('Default Content'),
@@ -393,21 +407,17 @@ function embed_widgets_ui_default_settings_form() {
     '#type' => 'textfield',
     '#title' => t('Title'),
     '#description' => t('This is the title that will be displayed if its content is no longer available.'),
-    '#options' => $options,
     '#default_value' => variable_get('embed_widgets_default_title', t('Content unavailable')),
   );
   $form['widget_content']['embed_widgets_default_content'] = array(
-    '#type' => 'textarea',
+    '#type' => 'text_format',
+    '#base_type' => 'textarea',
     '#title' => t('Content'),
     '#description' => t('This is the content that will be displayed if its content is no longer available.'),
-    '#options' => $options,
     '#default_value' => variable_get('embed_widgets_default_content', t('The content for this widget is no longer available.')),
+    '#format' => NULL,
   );
 
-  $filter = variable_get('embed_widgets_default_content_filter', FILTER_FORMAT_DEFAULT);
-  $form['widget_content']['embed_widgets_default_content_filter'] = filter_form($filter);
-  
-  
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save configuration'),
@@ -426,8 +436,8 @@ function embed_widgets_ui_default_settings_form() {
  */
 function embed_widgets_ui_default_settings_form_submit($form, &$form_state) {
   $settings = array();
-  if($form_state['values']['op'] == $form_state['values']['reset']) {
-    embed_widget::default_settings($settings, true);
+  if ($form_state['values']['op'] == $form_state['values']['reset']) {
+    embed_widget::default_settings($settings, TRUE);
     variable_del('embed_widgets_default_title');
     variable_del('embed_widgets_default_content');
     return;
@@ -435,11 +445,11 @@ function embed_widgets_ui_default_settings_form_submit($form, &$form_state) {
   foreach ($form_state['values']['widget']['settings'] as $name => $value) {
     $settings[$name] = $value;
   }
-  
+
   variable_set('embed_widgets_default_title', $form_state['values']['widget_content']['embed_widgets_default_title']);
   variable_set('embed_widgets_default_content', $form_state['values']['widget_content']['embed_widgets_default_content']);
   variable_set('embed_widgets_default_content_filter', $form_state['values']['format']);
-  
+
   drupal_set_message(t("Your settings have been saved."));
   embed_widget::default_settings($settings);
 }
diff --git a/includes/base/embed_widget.inc b/includes/base/embed_widget.inc
index 53360bc..418ee38 100644
--- a/includes/base/embed_widget.inc
+++ b/includes/base/embed_widget.inc
@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * An object containing all the data and member functions required for a widget.
  */
 class embed_widget {
@@ -150,9 +151,13 @@ class embed_widget {
    */
   protected static function db_load($hash) {
     if (is_string($hash)) {
-      $result = db_query("SELECT * FROM {embed_widgets} WHERE hash = '%s'", $hash);
+      $query = db_select('embed_widgets', 'ew')
+        ->condition('hash', $hash);
+      $result = $query->fields('ew', $query->getFields())
+        ->execute()
+        ->fetchAssoc();
       if ($result) {
-        $embed_widget = db_fetch_object($result);
+        $embed_widget = (object) $result;
       }
       if (isset($embed_widget->wid)) {
         $embed_widget->settings = unserialize($embed_widget->settings);
@@ -227,8 +232,8 @@ class embed_widget {
       $widgets = array();
     }
 
-    if ($action == 'get') {
-      return $widgets['hash'];
+    if (($action == 'get') && isset($widgets[$hash])) {
+      return $widgets[$hash];
     }
     elseif ($action == 'update' && is_object($hash)) {
       $widgets[$hash->encoded] = $hash;
@@ -299,9 +304,25 @@ class embed_widget {
    *   TRUE on success; FALSE on failure.
    */
   public static function decode($encoded_widget) {
+    $cache_id = $id = $delta = NULL;
     // Decode widget.
-    list($encoded_widget, $cache_id) = explode("_._", $encoded_widget, 3);
-    list($hash, $id, $delta) = explode("-", $encoded_widget, 3);
+    $exploded = explode("_._", $encoded_widget, 3);
+    if (sizeof($exploded) > 1) {
+      list($encoded_widget, $cache_id) = $exploded;
+    }
+    $exploded = explode("-", $encoded_widget, 3);
+    switch (sizeof($exploded)) {
+      case 3:
+        list($hash, $id, $delta) = $exploded;
+        break;
+      case 2:
+        list($hash, $id) = $exploded;
+        break;
+      case 1:
+      default:
+        $hash = $encoded_widget;
+        break;
+    }
 
     $info = embed_widgets_get_info();
     $hashes = $info['hashes'];
@@ -370,7 +391,7 @@ class embed_widget {
   }
 
   protected function load_content() {
-    return true;
+    return TRUE;
   }
 
   protected function get_title() {
@@ -378,7 +399,7 @@ class embed_widget {
   }
 
   public function check_access() {
-    return true;
+    return TRUE;
   }
 
   /**
@@ -405,7 +426,7 @@ class embed_widget {
    *   The URL to a widget's embed file as a string.
    */
   public function get_embed_url() {
-    $path = 'embed-widgets/' . $cache . $this->encode() . '/embed/' . implode('/', $this->params);
+    $path = 'embed-widgets/' . $this->encode() . '/embed/' . implode('/', $this->params);
     return url($path, array('absolute' => TRUE));
   }
 
@@ -416,7 +437,7 @@ class embed_widget {
    *   The URL to a widget's content as a string.
    */
   public function get_content_url() {
-    $path = 'embed-widgets/' . $cache . $this->encode() . '/content/' . implode('/', $this->params);
+    $path = 'embed-widgets/' . $this->encode() . '/content/' . implode('/', $this->params);
     return url($path, array('absolute' => TRUE));
   }
 
@@ -438,12 +459,12 @@ class embed_widget {
    *   The URL to a widget's share page.
    */
   public function get_share_url() {
-    global $widgets_mode;
+    global $_embed_widgets_mode;
     $path = 'embed-widgets/' . $this->encode() . '/share/' . implode('/', $this->params);
-    if (empty($widgets_mode)) {
+    if (empty($_embed_widgets_mode)) {
       return url($path, array('absolute' => TRUE));
     }
-    return url($path, array('absolute' => TRUE, 'query' => array('widgets_mode' => $widgets_mode)));
+    return url($path, array('absolute' => TRUE, 'query' => array('widgets_mode' => $_embed_widgets_mode)));
   }
 
   /**
@@ -524,9 +545,9 @@ class embed_widget {
   }
 
   protected function get_args() {
-    global $widgets_mode;
+    global $_embed_widgets_mode;
 
-    //if (isset($widgets_mode)) {
+    //if (isset($_embed_widgets_mode)) {
       $args = arg();
       if ($args[0] == 'embed-widgets') {
         if (count($args) > 3) {
@@ -552,7 +573,7 @@ class embed_widget {
     if ($refresh) {
       variable_del('embed_widgets_widget_defaults');
     }
-    else if ($settings && is_array($settings)) {
+    elseif ($settings && is_array($settings)) {
       return variable_set('embed_widgets_widget_defaults', $settings);
     }
     return variable_get('embed_widgets_widget_defaults', array('width' => 300, 'height' => 300));
diff --git a/includes/base/widget_format.inc b/includes/base/widget_format.inc
index fef0c2b..17b542c 100644
--- a/includes/base/widget_format.inc
+++ b/includes/base/widget_format.inc
@@ -2,6 +2,7 @@
 
 
 /**
+ * @file
  * An abstract object providing the member functions required for widget formats.
  */
 abstract class widget_format {
@@ -9,14 +10,14 @@ abstract class widget_format {
   public $id;
   public $description;
   public $filename;
-   
+
   abstract static public function info();
   abstract static public function embed_file(embed_widget $widget);
   abstract static public function embed_code(embed_widget $widget);
   static public function theme() {
     return array();
   }
-  
+
 //  function __construct() {
 //    $this->id = get_class($this);
 //    $info = call_user_func($this->id . '::info');
@@ -28,11 +29,11 @@ abstract class widget_format {
 //    $this->description = $info['description'];
 //    //$this->filename = $info['filename'];
 //  }
-  
+
   static public function settings_form() {
     return array();
   }
-  
+
   static public function admin_settings() {
     return array();
   }
diff --git a/includes/base/widget_platform.inc b/includes/base/widget_platform.inc
index cde8fd9..4d071cd 100644
--- a/includes/base/widget_platform.inc
+++ b/includes/base/widget_platform.inc
@@ -3,6 +3,7 @@
 // Possible platforms: http://www.clearspring.com/docs/tech/distribution/destinations
 
 /**
+ * @file
  * An object providing the member functions required for widget platforms.
  */
 abstract class widget_platform {
@@ -10,28 +11,28 @@ abstract class widget_platform {
   public $id;
   public $description;
   public $js_variables;
-  
+
   protected $parent_widget;
-  
+
   //public $allowed_formats = array();
-   
+
   static public function check_format($format) {
     $info = $this->info();
     return (is_string($format) && in_array($format, $info['formats']));
   }
-  
-  
+
+
   abstract static public function info();
   abstract static public function live_preview($widget);
-  
+
   static public function platform_file($widget) {
-    return false;
+    return FALSE;
   }
-  
+
   static public function theme() {
     return array();
   }
-  
+
   static public function settings_form() {
     return array();
   }
diff --git a/includes/base/widget_source.inc b/includes/base/widget_source.inc
index d0d1cd2..dc190a7 100644
--- a/includes/base/widget_source.inc
+++ b/includes/base/widget_source.inc
@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * An abstract object providing the member functions required for widget source objects.
  */
 abstract class widget_source {
@@ -10,7 +11,7 @@ abstract class widget_source {
   public $content;
   public $params;
   protected $settings = array();
-  
+
   public function __construct($id = NULL, $delta = NULL) {
     list($this->type) = explode("_", get_class($this));
     if (is_array($id)) {
@@ -21,7 +22,7 @@ abstract class widget_source {
       $this->delta = $delta;
     }
   }
-  
+
   public function set_variable($name, $value) {
       $this->settings[$name] = $value;
   }
@@ -32,26 +33,26 @@ abstract class widget_source {
   abstract static public function info();
   abstract public function check_access();
   abstract protected function build();
-  
+
   public function save($wid, $query_type) {
     return TRUE;
   }
-  
+
   public function get_content() {
     if (!isset($content)) {
       $this->content = $this->build();
     }
     return $this->content;
   }
-  
+
   static public function admin_settings_form() {
     return array();
   }
-  
+
   public function parameters_form() {
     $form = array();
     return $form;
-    
+
     // Generate in-widget form for configuration and sharing.
     /*  http://www.clearspring.com/docs/website/widget-console#parameters
      *  User editable: When the widget is shared, the user will have the option of changing the value of this parameter for their new installation (see image above).
@@ -61,6 +62,6 @@ abstract class widget_source {
         User Facing Label: The user-friendly name of the parameter, which end users will see when getting their own instance of the widget.
         Type: The data type of the variable, which is used to control the type of input the user is allowed to specify. You can use this parameter to, for example, offer a list of choices to the end user, or to allow them to type text freely.
      */
-    
+
   }
 }
\ No newline at end of file
diff --git a/includes/format/iframe/iframe.css b/includes/format/iframe/iframe.css
index 13755e9..226465d 100644
--- a/includes/format/iframe/iframe.css
+++ b/includes/format/iframe/iframe.css
@@ -1,43 +1,44 @@
 
 /**
  * @file widgets.css
- 
+
  * Template for widget CSS.
  */
 
-body {
-  background-color: transparent !important;
-}
-
-.widget-title {
-  display:block;
-}
-
-#widget-tabs-wrapper {
-  border-bottom:1px solid #E9EFF3;
-  margin:0;
-  padding:0;
-}
-
-.widget-container {
-  background: #FFFFFF;
+#page-wrapper,
+#widget-wrapper {
+  background: #FFFFFF !important;
   border: 1px solid #D9EAF5;
   margin: 0 0;
   padding:5px;
   overflow: auto;
+  width: 95%;
+  height: 95%;
+  min-height: 0 !important;
+  min-width: 0 !important;
 }
 
-.embed-widget .node {
-  border-bottom:medium none;
-  margin:0;
-  padding:0.2em;
-}
-
-#share-container,
-#back-container {
+/**
+ * Float the 'share' link to the bottom left.
+ */
+#embed-widgets-share-link {
   background-color: #FFFFFF;
   border: 1px solid #D9EAF5;
-  bottom: 0;
+  bottom: 5%;
   padding: 2px 5px;
   position: fixed;
 }
+
+/**
+ * Hide the administrative toolbar.
+ */
+body {
+  background-color: transparent !important;
+  padding-top:0px !important;
+}
+
+body #toolbar,
+#header,
+#footer-wrapper {
+  display: none !important;
+}
diff --git a/includes/format/iframe/iframe.inc b/includes/format/iframe/iframe.inc
index 75a74fa..93ed147 100644
--- a/includes/format/iframe/iframe.inc
+++ b/includes/format/iframe/iframe.inc
@@ -1,5 +1,9 @@
 <?php
 
+/**
+ * @file
+ * Defines the iFrame widget class.
+ */
 class iframe extends widget_format {
 
   static public function info() {
@@ -9,11 +13,11 @@ class iframe extends widget_format {
       'path' => drupal_get_path('module', 'embed_widgets') . '/includes/format/iframe',
       //'embed_path' => drupal_get_path('module', 'embed_widgets'),
       'embed_file' => 'iframe.js',
-      'embed_header' => 'Content-type: text/javascript; charset=utf-8',
+      'embed_header' => array('name' => 'Content-type', 'value' => 'text/javascript; charset=utf-8'),
       'css' => array('iframe.css'),
     );
   }
-  
+
   static public function theme() {
     $path = drupal_get_path('module', 'embed_widgets');
     return array(
@@ -25,7 +29,7 @@ class iframe extends widget_format {
       ),
     );
   }
-  
+
   static public function settings_form(embed_widget $widget) {
     $form = array();
     $form['format']['iframe']['width'] = array(
@@ -48,7 +52,7 @@ class iframe extends widget_format {
     );
     return $form;
   }
-  
+
   static public function admin_settings() {
     $form = array();
     $form['iframe'] = array(
@@ -56,14 +60,14 @@ class iframe extends widget_format {
       '#title' => t('iFrame Settings'),
       '#collapsible' => FALSE,
     );
-  
+
     $form = system_settings_form($form);
     return $form;
   }
 
   static public function embed_file(embed_widget $widget) {
     $format_info = iframe::info();
-    
+
     // Make variables available to JavaScript.
     $widget_context = new stdClass();
     $widget_context->wid = $widget->encode();
@@ -71,31 +75,31 @@ class iframe extends widget_format {
     $widget_context->width = $widget->get_variable('width');
     $widget_context->height = $widget->get_variable('height');
     $widget_context->jquery = url('misc/jquery.js', array('absolute' => TRUE));
-    $widget_context->new_placement = url('embed-widgets/js/get-code/' . $widget->wid . '/' . $widget->iid, array('absolute' => TRUE));
+//     $widget_context->new_placement = url('embed-widgets/js/get-code/' . $widget->wid . '/' . $widget->delta, array('absolute' => TRUE));
     $widget_context->base_url = url('', array('absolute' => TRUE));
-    
-    $file = 'widgetContext = ' . drupal_to_js($widget_context) . "\n";
-    
+
+    $file = 'widgetContext = ' . drupal_json_encode($widget_context) . "\n";
+
     $file .= file_get_contents('./' . $format_info['path'] . '/' . $format_info['embed_file']);
-    drupal_set_header($format_info['embed_header']);
+    drupal_add_http_header($format_info['embed_header']['name'], $format_info['embed_header']['value']);
     $path = $format_info['path'] . '/' . $format_info['embed_file'];
-    
+
     return $file;
   }
-  
+
   static public function embed_code(embed_widget $widget, $noscript = FALSE) {
     $format_info = iframe::info();
-    
+
     if (!empty($noscript)) {
       $output = '<div id="widget-embed-wrapper">';
-      $output .= '<iframe frameborder="0" width="'. $widget->get_variable('width') . '" height="'. $widget->get_variable('height') . '" id="drupal-embed" src="' . $widget->get_content_url() . '"></iframe>';
+      $output .= '<iframe frameborder="0" width="' . $widget->get_variable('width') . '" height="' . $widget->get_variable('height') . '" id="drupal-embed" src="' . $widget->get_content_url() . '"></iframe>';
       $output .= '</div>';
       return $output;
     }
-    
+
     return '<script id="widget-embed-script-' . $widget->encode() . '" src="' . $widget->get_embed_url($format_info['embed_file']) . '"></script>';
   }
-  
 
-  
+
+
 }
diff --git a/includes/format/iframe/iframe.js b/includes/format/iframe/iframe.js
index 9307bd1..6892fda 100644
--- a/includes/format/iframe/iframe.js
+++ b/includes/format/iframe/iframe.js
@@ -8,14 +8,14 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 	  width: widgetContext['width'],
 	  height: widgetContext['height'],
 	  jquery: widgetContext['jquery'],
-	  new_placement: widgetContext['new_placement'],
+// 	  new_placement: widgetContext['new_placement'],
 	  newID: false,
 	  base_url: widgetContext['base_url']
 	};
 
 	if (typeof embedWidgetInsert == 'undefined') {
 	  embedWidgetInsert = function () {
-		  
+
 //        jQuery now loads, so we can use it for embed code interface.
 //		  $(document).ready(function(){
 //              $("").appendTo("body");
@@ -25,9 +25,9 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 		  for (var i in DrupalEmbed) {
 		    if (!DrupalEmbed[i]['processed']) {
 		      DrupalEmbed[i]['processed'] = true;
-		      
+
 		      var separator = DrupalEmbed[i].src.indexOf('?') == -1 ? '?' : '&';
-		      
+
 		      // Keep track of how many widgets are embedded in this document.
 		      if(undefined===window.widget_count){
 		        window.widget_count = 0;
@@ -35,11 +35,11 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 		      else {
 		        widget_count++;
 		      }
-		      
+
 		      // Use unique ID for each widget on the page.
 		      var script = document.getElementById('widget-embed-script-' + DrupalEmbed[i].wid);
 		      script.setAttribute('id', 'widget-embed-script-' + DrupalEmbed[i].wid + widget_count);
-		      
+
 		      // Create iframe element.
 		      var div = document.createElement('div');
 		      div.setAttribute('id', 'widget-embed-container' + widget_count);
@@ -50,7 +50,7 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 		      iframe.setAttribute('height', DrupalEmbed[i].height);
 		      //iframe.setAttribute('style', "border:1px solid #D9EAF5;");
 		      iframe.setAttribute('scrolling', 'no');
-		      
+
 		      if (DrupalEmbed[i].height) {
 		        iframe.myHeight = DrupalEmbed[i].height;
 		      }
@@ -58,7 +58,7 @@ if (document.getElementsByTagName && document.createElement && document.createTe
                 iframe.myWidth = DrupalEmbed[i].width;
 		      }
 		      iframe.setAttribute('src', DrupalEmbed[i].src + separator + 'widgets_mode=' + DrupalEmbed[i].wid);
-		      
+
 		      //var embed_link = document.createElement('a');
 		      //embed_link.setAttribute('id', 'widget-embed-link' + widget_count);
 		      //embed_link.setAttribute('href', 'javascript:');
@@ -66,26 +66,26 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 		      //embed_link.innerHTML = "Embed";
 		      //var link_wrapper = document.createElement('div');
 		      //var code_wrapper = document.createElement('div');
-		      
+
 		      //var input = document.createElement('input');
         //input.setAttribute('type', 'text');
         //input.setAttribute('value', '<script id="widget-embed-script-' + DrupalEmbed[i].wid +'" src="' + DrupalEmbed[i].base_url + '/embed-widgets/embed/' + DrupalEmbed[i].wid + '/iframe.js"></script>');
         //input.setAttribute('style', 'width: 90%;');
         //input.setAttribute('onClick', "javascript:this.focus(); this.select();");
-        
+
         //var desc_wrapper = document.createElement('div');
         //desc_wrapper.setAttribute('style', 'font-size: 10px; line-height: 150%;');
         //desc_wrapper.innerHTML = "Share by pasting this code into your website:";
-		      
-		      
+
+
 		      //code_wrapper.innerHTML = "Code goes here.";
 	//	      var newID = false;
-		      
+
 //		      $(link_wrapper).click(function () {
 //		          //$(code_wrapper).slideDown();
 //		          if ($(code_wrapper).is(":hidden")) {
 //		            $(code_wrapper).show("slow");
-//		            
+//
 ////		            if (DrupalEmbed[i].newID == false) {
 ////		              DrupalEmbed[i].newID = true;
 ////		              $.getJSON(DrupalEmbed[i].new_placement,
@@ -97,39 +97,39 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 ////		            	  code_wrapper.appendChild(input);
 ////		            	  //<script id="widget-embed-script-bG8ueUV1238UHZYek01c65445sb2NhbGhvc3Q-4-4" src="http://localhost/embed-widgets/embed/bG8ueUV1238UHZYek01c65445sb2NhbGhvc3Q-4-4/iframe.js"></script>
 ////	                  });
-//		              
+//
 //		            }
 //
 //		          } else {
 //		            $(code_wrapper).slideUp();
 //		          }
 //		      });
-		      
+
 //		      $(code_wrapper).ready(function () {
 //		    	    $(code_wrapper).hide();
 //		    	});
 
 
-		      
+
 		      // Set correct iframe height each time content in iframe changes.
 		      iframe.onload = function () {
 		  	        var iframeDocument = this.contentDocument ? this.contentDocument : (this.contentWindow ? this.contentWindow.document : null);
-		  	        
+
 		  	        if (iframeDocument) {
 		  	          //$("#container > *", iframeDocument).css({'max-width' : (this.myWidth - 20) + 'px'});
 		  	          //var height = iframeDocument.innerHeight || iframeDocument.body.scrollHeight;  // Does not work cross-domain
 		  	          //var width = iframeDocument.innerWidth || iframeDocument.body.scrollWidth;
 		  	          var height = this.myHeight;
 		  	          var width = this.myWidth;
-		  	          
+
 //		  	          if (height > parseInt(this.myHeight, 10)) {
 //		  	            width += 14;
 //		  	          }
-		  	          
+
 //		  	          if (this.myHeight) {
 //		  	            //iframeDocument.getElementById('container').style.height = this.myHeight + 'px';
 //		  	            height = parseInt(this.myHeight, 10) + 15;
-//		  	          }		  	          
+//		  	          }
 //		  	          else {
 //		  	        	//iframeDocument.getElementById('container').style.height = (height) + 'px';
 //		  	        	height = iframeDocument.height || iframeDocument.body.scrollHeight;
@@ -143,10 +143,10 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 		  	          this.setAttribute('width', width);
 		  	          //$('#widget-embed-container' + widget_count).css({'width' : (width) + 'px', 'display' : 'block'});
 		  	          //this.parentNode.setAttribute('height', height);
-		  	          
+
 		  	        }
 		      };
-		      
+
 		      // Insert iframe into document.
 		      script.parentNode.insertBefore(iframe, script);
 		      //script.parentNode.insertBefore(div, script);
@@ -159,15 +159,15 @@ if (document.getElementsByTagName && document.createElement && document.createTe
 		      //$(code_wrapper).hide();
 		      //code_wrapper.appendChild(form);
 		      //code_wrapper.appendChild(input);
-		      
+
 
 		    }
 		  }
 	  };
 	}
-	
-  if (typeof jQuery == 'undefined') {  
-    var headID = document.getElementsByTagName("head")[0];         
+
+  if (typeof jQuery == 'undefined') {
+    var headID = document.getElementsByTagName("head")[0];
     var newScript = document.createElement('script');
     newScript.type = 'text/javascript';
     newScript.onload = embedWidgetInsert;
diff --git a/includes/format/iframe/iframe.tpl.php b/includes/format/iframe/iframe.tpl.php
index 3b90fe4..b91a6ec 100644
--- a/includes/format/iframe/iframe.tpl.php
+++ b/includes/format/iframe/iframe.tpl.php
@@ -1,43 +1,47 @@
 <?php
-?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
-  <head>
-    <title><?php print $head_title ?></title>
-    <?php print $head ?>
-    <?php print $styles ?>
-    <?php print $scripts ?>
-    <style type="text/css">
-      .widget-container {
-        height: <?php print $height - 12 ?>px;
-      }
-    </style>
-  </head>
-  <body class="<?php print $body_classes; ?>">
-
-<!-- Layout -->
-
-
-    <div id="container" class="clear-block widget-container">
-          <?php //print $breadcrumb; ?>
-          <?php if ($tabs): print '<div id="widget-tabs-wrapper" class="clear-block">'; endif; ?>
-          <?php if ($title): print '<h3 id="widget-title"'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h3>'; endif; ?>
-          <?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
-          <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
-          <?php if ($show_messages && $messages): print $messages; endif; ?>
-          <?php print $help; ?>
-          <div class="clear-block">
-            <?php print $content ?>
-          </div>
-          
-          <?php print $feed_icons ?>
-    </div> <!-- /container -->
-    <div id="share-container">
-      <?php print $share_widget ?>
-    </div>
-
-<!-- /layout -->
-
-  <?php print $closure ?>
-  </body>
-</html>
+  /**
+   * @file
+   * Display the widget in an iFrame.
+   */
+?>
+<div id="widget-wrapper"><div id="widget">
+  <div class="element-invisible">
+    <?php print render($page['page_top']); ?>
+  </div>
+
+  <?php if ($messages): ?>
+    <div id="messages"><div class="section clearfix">
+      <?php print $messages; ?>
+    </div></div> <!-- /.section, /#messages -->
+  <?php endif; ?>
+
+  <div id="main-wrapper" class="clearfix"><div id="main" class="clearfix">
+
+    <div id="content" class="column"><div class="section">
+      <a id="main-content"></a>
+      <?php print render($title_prefix); ?>
+      <?php if ($title): ?>
+        <h2 id="title">
+          <?php print $title; ?>
+        </h1>
+      <?php endif; ?>
+      <?php print render($title_suffix); ?>
+      <?php if ($tabs): ?>
+        <div class="tabs">
+          <?php print render($tabs); ?>
+        </div>
+      <?php endif; ?>
+      <?php print render($page['help']); ?>
+
+      <?php print embed_widgets_alter_links(render($page['content'])); ?>
+      <?php print $feed_icons; ?>
+
+    </div></div> <!-- /.section, /#content -->
+
+  </div></div> <!-- /#main, /#main-wrapper -->
+
+  <div class="element-invisible">
+    <?php print render($page['page_bottom']); ?>
+  </div>
+
+</div></div> <!-- /#widget, /#widget-wrapper -->
diff --git a/includes/platform/googlegadget.inc b/includes/platform/googlegadget.inc
index ca34464..4f2aec5 100644
--- a/includes/platform/googlegadget.inc
+++ b/includes/platform/googlegadget.inc
@@ -1,13 +1,17 @@
 <?php
 
+/**
+ * @file
+ * Define the Google Gadget platform widget.
+ */
 class googlegadget extends widget_platform {
-  
+
   public $name;
   public $id;
   public $description;
   public $format;
   public $filename;
-   
+
   static public function info() {
     return array(
       'title' => t('Google Gadget'),
@@ -16,7 +20,7 @@ class googlegadget extends widget_platform {
       'share_method' => 'link',
     );
   }
-  
+
   static public function theme() {
     return array(
       'googlegadget' => array(
@@ -26,10 +30,10 @@ class googlegadget extends widget_platform {
       ),
     );
   }
-  
+
   static public function code($widget) {
     //$format_info = call_user_func($this->format . '::info');
-    switch($widget->format) {
+    switch ($widget->format) {
       case 'iframe':
         $code = '<script src="http://www.gmodules.com/ig/ifr?url=' . $widget->get_content_url() . '&amp;synd=open&amp;w=' . $widget->get_variable('width') . '&amp;h=' . $widget->get_variable('height') . '&amp;title=' . $widget->get_variable('title') . '&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>';
         break;
@@ -37,16 +41,16 @@ class googlegadget extends widget_platform {
         $code = '';
         break;
     }
-    
+
     return $code;
   }
-  
+
   static public function link(embed_widget $widget) {
     return 'http://fusion.google.com/ig/add?synd=open&source=ggyp&moduleurl=' . $widget->get_platform_url();
   }
-  
+
   static public function live_preview($widget) {
-    switch($widget->format) {
+    switch ($widget->format) {
       case 'iframe':
         if (function_exists($widget->format . '::embed_code_noscript')) {
           $code = call_user_func($widget->format . '::embed_code_noscript', $widget);
@@ -56,21 +60,21 @@ class googlegadget extends widget_platform {
         $code = '';
         break;
     }
-    
+
     return $code;
   }
-  
+
   static public function platform_file($widget) {
-    drupal_set_header('Content-type: text/xml; charset=utf-8');
+    drupal_add_http_header('Content-type', 'text/xml; charset=utf-8');
     return theme('googlegadget', $widget);
   }
-  
+
   static public function settings_form() {
     $form = array();
     $form['google_gadget'] = array(
       '#type' => 'fieldset',
       '#title' => t('Google Gadget Settings'),
-      '#description' => t("The settings below are used as the default settings for Google Gadgets. Some of these fields are required to submit your gadget to Google's content directory. See !link for more information.", array('!link' => l('this page', 'http://code.google.com/apis/gadgets/docs/legacy/publish.html#Submitting'))),
+      '#description' => t("The settings below are used as the default settings for Google Gadgets. Some of these fields are required to submit your gadget to Google's content directory. See !link for more information.", array('!link' => l(t('this page'), 'http://code.google.com/apis/gadgets/docs/legacy/publish.html#Submitting'))),
       '#collapsible' => TRUE,
     );
     $form['google_gadget']['embed_widgets_google_gadgets_author'] = array(
@@ -107,7 +111,7 @@ class googlegadget extends widget_platform {
     );
     return $form;
   }
-  
+
 
 }
 
diff --git a/includes/platform/html.inc b/includes/platform/html.inc
index ff3223c..a13907b 100644
--- a/includes/platform/html.inc
+++ b/includes/platform/html.inc
@@ -1,7 +1,11 @@
 <?php
 
+/**
+ * @file
+ * Define the HTML platform widget class.
+ */
 class html extends widget_platform {
-    
+
   static public function info() {
     return array(
       'title' => t('HTML'),
@@ -10,14 +14,14 @@ class html extends widget_platform {
       'share_method' => 'code',
     );
   }
-  
+
   static public function theme() {
     return array();
   }
-  
+
   static public function code($widget, $no_script = FALSE) {
     //$format_info = call_user_func($this->format . '::info');
-    switch($widget->format) {
+    switch ($widget->format) {
       case 'iframe':
         $code = call_user_func($widget->format . '::embed_code', $widget, $no_script);
         break;
@@ -25,12 +29,12 @@ class html extends widget_platform {
         $code = '';
         break;
     }
-    
+
     return $code;
   }
-  
+
   static public function live_preview($widget) {
-    switch($widget->format) {
+    switch ($widget->format) {
       case 'iframe':
         if (function_exists($widget->format . '::embed_code_noscript')) {
           $code = call_user_func($widget->format . '::embed_code_noscript', $widget);
@@ -40,12 +44,12 @@ class html extends widget_platform {
         $code = '';
         break;
     }
-    
+
     return $code;
   }
-    
+
 //  public function settings_form() {  }
 //  public function admin_settings() {  }
-  
+
 }
 
diff --git a/includes/widgets/embed_widget_block.inc b/includes/widgets/embed_widget_block.inc
index b27415c..47b6062 100644
--- a/includes/widgets/embed_widget_block.inc
+++ b/includes/widgets/embed_widget_block.inc
@@ -1,15 +1,13 @@
 <?php
 
-require_once drupal_get_path('module', 'embed_widgets') ."/embed_widgets.module";
-spl_autoload_register('embed_widgets_autoload');
-
 /**
+ * @file
  * An object containing all the data and member functions to provide block content to a widget.
  */
 class embed_widget_block extends embed_widget {
-  
+
   protected $block = NULL;
-  
+
   static public function info() {
     return array(
       'title' => t('Block'),
@@ -17,31 +15,44 @@ class embed_widget_block extends embed_widget {
       'name' => 'block',
     );
   }
-  
+
   protected function load_content() {
     if (empty($this->block)) {
       $this->block = module_invoke($this->source_id, 'block', 'view', $this->source_delta);
     }
     return isset($this->block['content']);
   }
-  
+
   protected function view_content() {
     return isset($this->block['content']) ? $this->block['content'] : FALSE;
   }
-  
+
   protected function get_title() {
     return isset($this->block['subject']) ? $this->block['subject'] : FALSE;
   }
-  
+
   public function check_access() {
     global $user, $theme;
-    
+
     $rids = array_keys($user->roles);
 
-    return db_result(db_query(db_rewrite_sql("SELECT DISTINCT b.status FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.module = '%s' AND b.delta = '%s' AND b.theme = '%s' AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), $this->source_id, $this->source_delta, $theme, $rids));
+    $db_or = db_or()->condition('r.rid', $rids, 'IN')
+      ->isNull('r.rid');
+
+    $query = db_select('blocks', 'b');
+    $query->leftJoin('blocks_roles', 'r', 'b.module = r.module AND b.delta = r.delta');
+    $query->fields('b', array('status'))
+      ->condition('b.module', $this->source_id)
+      ->condition('b.delta', $this->source_delta)
+      ->condition('b.theme', $theme)
+      ->condition($db_or)
+      ->orderBy('b.region')
+      ->orderBy('b.weight');
+    $query->addTag('block_access');
 
+    return $query->execute();
   }
-  
+
   static public function admin_settings_form() {
     $form = array();
     $form['block'] = array(
@@ -57,5 +68,5 @@ class embed_widget_block extends embed_widget {
     );
     return $form;
   }
-  
+
 }
diff --git a/includes/widgets/embed_widget_callback.inc b/includes/widgets/embed_widget_callback.inc
index 41347ea..d6b2be4 100644
--- a/includes/widgets/embed_widget_callback.inc
+++ b/includes/widgets/embed_widget_callback.inc
@@ -1,15 +1,16 @@
 <?php
 
 /**
+ * @file
  * An object containing all the data and member functions to allow a user function to provide widget content.
  */
 class embed_widget_callback extends embed_widget {
-    
+
   protected $content = NULL;
   protected $callback = NULL;
   protected $access_callback = NULL;
   protected $file = NULL;
-  
+
   static public function info() {
     return array(
       'title' => t('Callback'),
@@ -17,7 +18,7 @@ class embed_widget_callback extends embed_widget {
       'name' => 'callback',
     );
   }
-  
+
   /**
    * Constructor. Accepts either a numeric or encrypted widget ID.
    *
@@ -30,7 +31,7 @@ class embed_widget_callback extends embed_widget {
    */
   function __construct($type, $module, $delta, $platform = 'html', $format = 'iframe', $cache_id = NULL) {
     parent::__construct($type, $module, $delta, $platform, $format, $cache_id = NULL);
-    
+
     $info = embed_widgets_module_widget($module, $delta);
     $this->callback = is_string($info['callback']) ? $info['callback'] : NULL;
     $this->access_callback = is_string($info['access_callback']) ? $info['access_callback'] : NULL;
@@ -38,7 +39,7 @@ class embed_widget_callback extends embed_widget {
     $this->title = is_string($info['title']) ? $info['title'] : NULL;
 
   }
-  
+
   protected function load_content() {
 //    if (isset($this->file)) {
 //      include $this->file;
@@ -54,18 +55,18 @@ class embed_widget_callback extends embed_widget {
     }
     return FALSE;
   }
-  
+
   protected function view_content() {
     if (!empty($this->content)) {
       return $this->content;
     }
     return FALSE;
   }
-  
+
   protected function get_title() {
     return $this->title;
   }
-  
+
   public function check_access() {
 //    if (isset($this->file)) {
 //      include $this->file;
diff --git a/includes/widgets/embed_widget_node.inc b/includes/widgets/embed_widget_node.inc
index 617fd9a..76f8eb0 100644
--- a/includes/widgets/embed_widget_node.inc
+++ b/includes/widgets/embed_widget_node.inc
@@ -1,12 +1,13 @@
 <?php
 
 /**
+ * @file
  * An object containing all the data and member functions to provide node content to a widget.
  */
 class embed_widget_node extends embed_widget {
-  
+
   protected $node;
-   
+
   static public function info() {
     return array(
       'title' => t('Node'),
@@ -14,7 +15,7 @@ class embed_widget_node extends embed_widget {
       'name' => 'node',
     );
   }
-  
+
   protected function load_content() {
     if (!isset($this->source_id)) {
       return FALSE;
@@ -25,29 +26,29 @@ class embed_widget_node extends embed_widget {
         $this->node = $node;
         return TRUE;
       }
-      
+
     }
     return FALSE;
   }
-  
+
   protected function view_content() {
     if (!empty($this->node)) {
-      return node_view($this->node, FALSE, TRUE);
+      return node_view($this->node, 'full');
     }
     return FALSE;
   }
-  
+
   protected function get_title() {
     return isset($this->node->title) ? $this->node->title : FALSE;
   }
-  
+
   public function check_access() {
     if (!empty($this->node)) {
       return node_access('view', $this->node);
     }
     return FALSE;
   }
-  
+
   static public function admin_settings_form() {
     $form = array();
     $form['node'] = array(
@@ -56,7 +57,7 @@ class embed_widget_node extends embed_widget {
       '#collapsible' => TRUE,
     );
     $content_types = array();
-    foreach (node_get_types() as $key => $type) {
+    foreach (node_type_get_types() as $key => $type) {
       $content_types[$key] = $type->name;
     }
     $form['node']['embed_widgets_content_types'] = array(
@@ -68,10 +69,10 @@ class embed_widget_node extends embed_widget {
     );
     return $form;
   }
-  
+
   static public function path_load() {
     $arg = arg();
-    if ($arg[0] == 'node' && is_numeric($arg[1])) {
+    if ($arg[0] == 'node' && arg(1) && is_numeric($arg[1])) {
       $node = menu_get_object();
       if (!empty($node)&& !empty($node->nid)) {
         $content_types = variable_get('embed_widgets_content_types', array());
@@ -86,5 +87,5 @@ class embed_widget_node extends embed_widget {
     }
     return NULL;
   }
-  
+
 }
\ No newline at end of file
diff --git a/includes/widgets/embed_widget_page.inc b/includes/widgets/embed_widget_page.inc
index dc80d53..bae8e24 100644
--- a/includes/widgets/embed_widget_page.inc
+++ b/includes/widgets/embed_widget_page.inc
@@ -1,13 +1,14 @@
 <?php
 
 /**
+ * @file
  * An object containing all the data and member functions to provide node content to a widget.
  */
 class embed_widget_page extends embed_widget {
-  
+
   protected $page;
   protected $path;
-   
+
   static public function info() {
     return array(
       'title' => t('Page'),
@@ -15,7 +16,7 @@ class embed_widget_page extends embed_widget {
       'name' => 'page',
     );
   }
-  
+
   /**
    * Constructor. Accepts either a numeric or encrypted widget ID.
    *
@@ -30,7 +31,7 @@ class embed_widget_page extends embed_widget {
     parent::__construct($type, $id, $delta, $platform, $format, $cache_id);
     $this->path = base64_decode($this->source_id);
   }
-  
+
   protected function load_content() {
     // Display a page
     // Adapted from print.module.
@@ -44,28 +45,28 @@ class embed_widget_page extends embed_widget {
     $node->body = menu_execute_active_handler($path);
     $node->title = $this->title;
     $node->path = $path;
-        
+
     // It may happen that a drupal_not_found is called in the above call
-    if (preg_match('/404 Not Found/', drupal_get_headers()) == 1) {
+    if (preg_match('/404 Not Found/', drupal_get_http_header()) == 1) {
       return FALSE;
     }
-    
+
     // Delete any links area
     $node->body = preg_replace("/\s*<div class=\"links\">.*?<\/div>/sim", "", $node->body);
 
     $path = empty($node->nid) ? $node->path : "node/$node->nid";
-  
+
     if (isset($node->type)) {
       $node_type = $node->type;
-  
+
       $by_author = ($node->name ? $node->name : variable_get('anonymous', t('Anonymous')));
       $by = t('By %author', array('%author' => $by_author));
       $page["submitted"] = theme_get_setting("toggle_node_info_$node_type") ? $by : "";
-  
+
       $created_datetime = format_date($node->created, 'small');
       $created = t('Created %date', array('%date' => $created_datetime));
       $page["created"] = theme_get_setting("toggle_node_info_$node_type") ? $created : "";
-  
+
       $page["type"] = $node->type;
     }
     else {
@@ -73,7 +74,7 @@ class embed_widget_page extends embed_widget {
       $page["created"] = "";
       $page["type"] = '';
     }
-  
+
     menu_set_active_item($path);
     $breadcrumb = drupal_get_breadcrumb();
     if (!empty($breadcrumb)) {
@@ -83,30 +84,30 @@ class embed_widget_page extends embed_widget {
     else {
       $page["breadcrumb"] = "";
     }
-  
+
     if (module_exists('taxonomy')) {
       $terms = taxonomy_link('taxonomy terms', $node);
       $page["taxonomy"] = theme('links', $terms);
     }
-  
+
     $page["content"] = $node->body;
-    
+
     if ($node->body == MENU_NOT_FOUND || $node->body == MENU_ACCESS_DENIED) {
       return FALSE;
     }
-    
+
     $this->page = $page;
     return TRUE;
   }
-  
+
   protected function view_content() {
     return $this->page['content'];
   }
-  
+
   protected function get_title() {
     return isset($this->page['title']) ? $this->page['title'] : FALSE;
   }
-  
+
   public function check_access() {
     $path = drupal_get_normal_path($this->path);
     $router_item = menu_get_item($path);
@@ -115,7 +116,7 @@ class embed_widget_page extends embed_widget {
     }
     return FALSE;
   }
-  
+
   static public function path_load() {
     $path = $_GET['q'];
     $widget = embed_widgets_new('page', base64_encode($path));
@@ -124,6 +125,6 @@ class embed_widget_page extends embed_widget {
     }
     return FALSE;
   }
-  
-    
+
+
 }
diff --git a/includes/widgets/embed_widget_view.inc b/includes/widgets/embed_widget_view.inc
index 504c923..0a16c9a 100644
--- a/includes/widgets/embed_widget_view.inc
+++ b/includes/widgets/embed_widget_view.inc
@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * An object containing all the data and member functions to provide view content to a widget.
  */
 class embed_widget_view extends embed_widget {
diff --git a/tests/embed_widget.test b/tests/embed_widget.test
index bd0e31b..76b4ece 100644
--- a/tests/embed_widget.test
+++ b/tests/embed_widget.test
@@ -1,13 +1,13 @@
 <?php
 
 /**
- * @file embed_widgets.test
+ * @file
  * Contains SimpleTests for Embed Widgets.
  */
 
 /**
-* Unit tests for embed_widget class.
-*/
+ * Unit tests for embed_widget class.
+ */
 class EmbedWidgetsEmbedWidgetTestCase extends DrupalWebTestCase {
 
   /**
@@ -20,23 +20,23 @@ class EmbedWidgetsEmbedWidgetTestCase extends DrupalWebTestCase {
       'group' => t('Embed Widgets'),
     );
   }
-  
+
   /**
-   * Implementation of setUp().
+   * Implements setUp().
    */
-  function setUp() {       
+  function setUp() {
     parent::setUp(
       'embed_widgets'
     );
   }
-  
+
   function tearDown() {
     // Do tear down tasks...
-  
+
     // Finally...
     parent::tearDown();
   }
-  
+
   /**
    * Build Widget
    */
@@ -47,36 +47,36 @@ class EmbedWidgetsEmbedWidgetTestCase extends DrupalWebTestCase {
 
     return $widget;
   }
-  
+
   function testWidgetCrud() {
-    
+
     $node = $this->drupalCreateNode();
     $widget = embed_widgets_new('node', $node->nid);
     $widget->title = $this->randomName(15);
-    
+
     $embed_widget = $widget;
-    
+
     // Save widget
     $create = $embed_widget->save();
     $this->assertEqual($create, SAVED_NEW, t('Widget saved'), t('Widget CRUD'));
     $this->pass(var_export($embed_widget, TRUE));
-    
+
     $widget = embed_widgets_new('node', $node->nid);
     $widget->load();
     $this->assertEqual($embed_widget->title, $widget->title, t('Widget loaded'), t('Widget CRUD'));
     $this->pass(var_export($widget, TRUE));
-    
+
     // Edit widget
     $widget->title = "Edited!";
     $updated = $widget->save();
     $this->assertEqual($updated, SAVED_UPDATED, t('Edited widget saved.'), t('Widget CRUD'));
     $this->pass(var_export($widget, TRUE));
-    
+
     $widget = embed_widgets_new('node', $node->nid);
     $widget->load();
     $this->pass(var_export($widget, TRUE));
     $this->assertEqual("Edited!", $widget->title, t('Edited widget loaded'), t('Widget CRUD'));
-    
+
     // Delete widget
     $result = $widget->delete();
     $this->assertTrue($result, t('Widget deleted'), t('Widget CRUD'));
diff --git a/tests/embed_widgets.test b/tests/embed_widgets.test
index 5a77765..71a9d87 100644
--- a/tests/embed_widgets.test
+++ b/tests/embed_widgets.test
@@ -1,13 +1,13 @@
 <?php
 
 /**
- * @file embed_widgets.test
+ * @file
  * Contains SimpleTests for Embed Widgets.
  */
 
 /**
-* Unit tests for embed_widget class.
-*/
+ * Unit tests for embed_widget class.
+ */
 class EmbedWidgetsModuleTestCase extends DrupalWebTestCase {
 
   /**
@@ -20,28 +20,28 @@ class EmbedWidgetsModuleTestCase extends DrupalWebTestCase {
       'group' => t('Embed Widgets'),
     );
   }
-  
+
   /**
-   * Implementation of setUp().
+   * Implements setUp().
    */
-  function setUp() {       
+  function setUp() {
     parent::setUp(
       'embed_widgets'
     );
   }
-  
+
   function tearDown() {
     // Do tear down tasks...
-  
+
     // Finally...
     parent::tearDown();
   }
-  
+
   function testWidgetInfo() {
     $info = embed_widgets_get_info();
     $this->assertTrue(count($info['format']) > 0, t('Widget format info found.'), t('Embed Widgets API'));
     $this->assertTrue(count($info['platform']) > 0, t('Widget platform info found.'), t('Embed Widgets API'));
     $this->assertTrue(count($info['sources']) > 0, t('Widget types info found.'), t('Embed Widgets API'));
     $this->assertTrue(count($info['hashes']) > count($info['sources']), t('Widget hashes computed.'), t('Embed Widgets API'));
-  }  
+  }
 }
diff --git a/views/embed_widgets.views.inc b/views/embed_widgets.views.inc
index 1d22c8a..8276657 100644
--- a/views/embed_widgets.views.inc
+++ b/views/embed_widgets.views.inc
@@ -5,7 +5,7 @@
  */
 
 /**
- * Implementation of hook_views_plugins().
+ * Implements hook_views_plugins().
  */
 function embed_widgets_views_plugins() {
   $data = array(
@@ -15,7 +15,7 @@ function embed_widgets_views_plugins() {
         'help' => t('Display the view as a widget. Offer a snippet of code that users can copy and paste to another web site.'),
         'handler' => 'embed_widgets_plugin_display_embed_widgets',
         'parent' => 'attachment',
-        'path' => drupal_get_path('module', 'embed_widgets') .'/views',
+        'path' => drupal_get_path('module', 'embed_widgets') . '/views',
         'uses hook menu' => TRUE,
         'theme' => 'views_view',
         'use ajax' => FALSE,
diff --git a/views/embed_widgets_plugin_display_embed_widgets.inc b/views/embed_widgets_plugin_display_embed_widgets.inc
index adc1b7f..13dd73e 100644
--- a/views/embed_widgets_plugin_display_embed_widgets.inc
+++ b/views/embed_widgets_plugin_display_embed_widgets.inc
@@ -24,7 +24,7 @@ class embed_widgets_plugin_display_embed_widgets extends views_plugin_display_at
     // TODO: Render widget with no javascript
     return $this->view->render();
   }
-  
+
   /**
    * Provide the default form for setting options.
    */
@@ -60,7 +60,7 @@ class embed_widgets_plugin_display_embed_widgets extends views_plugin_display_at
     switch ($form_state['section']) {
       case 'dimension':
         $this->set_option('width', $form_state['values']['width']);
-        $this->set_option('height', $form_state['values']['height']);       
+        $this->set_option('height', $form_state['values']['height']);
         break;
     }
   }
@@ -114,8 +114,8 @@ class embed_widgets_plugin_display_embed_widgets extends views_plugin_display_at
 
     // because of this, it is very very important that displays that can accept
     // attachments not also be attachments, or this could explode messily.
-    global $widgets_mode;
-    if (empty($widgets_mode)) {
+    global $_embed_widgets_mode;
+    if (empty($_embed_widgets_mode)) {
       $widget = embed_widgets_load('view', $this->view->name, $this->display->id);
       $widget->params = $args;
       $attachment = embed_widgets_share($widget);
diff --git a/widget-iframe.tpl.php b/widget-iframe.tpl.php
index ddf577c..b91a6ec 100644
--- a/widget-iframe.tpl.php
+++ b/widget-iframe.tpl.php
@@ -1,50 +1,47 @@
 <?php
-?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
-  <head>
-    <title><?php print $head_title ?></title>
-    <?php print $head ?>
-    <?php print $styles ?>
-    <?php print $scripts ?>
-    <style type="text/css">
-      .widget-container {
-        height: <?php print $height - 12 ?>px;
-      }
-    </style>
-  </head>
-  <body class="<?php print $body_classes; ?>">
-
-<!-- Layout -->
-
-
-    <div id="container" class="clear-block widget-container">
-          <?php //print $breadcrumb; ?>
-          <?php if ($tabs): print '<div id="widget-tabs-wrapper" class="clear-block">'; endif; ?>
-          <?php if ($title): print '<h3 id="widget-title"'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h3>'; endif; ?>
-          <?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
-          <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
-          <?php if ($show_messages && $messages): print $messages; endif; ?>
-          <?php print $help; ?>
-          <div class="clear-block">
-            <?php print $content ?>
-          </div>
-          
-          <?php print $feed_icons ?>
-    </div> <!-- /container -->
-
-    <?php if ($back_to_widget): ?>
-      <div id="back-container">
-        <?php print l(t('Back'), $widget_url); ?>
-      </div>
-    <?php else: ?>
-      <div id="share-container">
-        <?php print $share_widget ?>
-      </div>
-    <?php endif; ?>
-
-<!-- /layout -->
-
-  <?php print $closure ?>
-  </body>
-</html>
+  /**
+   * @file
+   * Display the widget in an iFrame.
+   */
+?>
+<div id="widget-wrapper"><div id="widget">
+  <div class="element-invisible">
+    <?php print render($page['page_top']); ?>
+  </div>
+
+  <?php if ($messages): ?>
+    <div id="messages"><div class="section clearfix">
+      <?php print $messages; ?>
+    </div></div> <!-- /.section, /#messages -->
+  <?php endif; ?>
+
+  <div id="main-wrapper" class="clearfix"><div id="main" class="clearfix">
+
+    <div id="content" class="column"><div class="section">
+      <a id="main-content"></a>
+      <?php print render($title_prefix); ?>
+      <?php if ($title): ?>
+        <h2 id="title">
+          <?php print $title; ?>
+        </h1>
+      <?php endif; ?>
+      <?php print render($title_suffix); ?>
+      <?php if ($tabs): ?>
+        <div class="tabs">
+          <?php print render($tabs); ?>
+        </div>
+      <?php endif; ?>
+      <?php print render($page['help']); ?>
+
+      <?php print embed_widgets_alter_links(render($page['content'])); ?>
+      <?php print $feed_icons; ?>
+
+    </div></div> <!-- /.section, /#content -->
+
+  </div></div> <!-- /#main, /#main-wrapper -->
+
+  <div class="element-invisible">
+    <?php print render($page['page_bottom']); ?>
+  </div>
+
+</div></div> <!-- /#widget, /#widget-wrapper -->
diff --git a/widget.tpl.php b/widget.tpl.php
index b9be3a1..16c675d 100644
--- a/widget.tpl.php
+++ b/widget.tpl.php
@@ -1,42 +1,56 @@
 <?php
-?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
-  <head>
-    <title><?php print $head_title ?></title>
-    <?php print $head ?>
-    <?php print $styles ?>
-    <?php print $scripts ?>
-    <!--[if lt IE 7]>
-      <?php print phptemplate_get_ie_styles(); ?>
-    <![endif]-->
-  </head>
-  <body>
-
-<!-- Layout -->
-
-
-    <div id="container" class="clear-block widget-container">
-
-      <div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
-          <?php //print $breadcrumb; ?>
-          <?php if ($tabs): print '<div id="widget-tabs-wrapper" class="clear-block">'; endif; ?>
-          <?php if ($title): print '<h3 id="widget-title"'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h3>'; endif; ?>
-          <?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
-          <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
-          <?php if ($show_messages && $messages): print $messages; endif; ?>
-          <?php print $help; ?>
-          <div class="clear-block">
-            <?php print $content ?>
-          </div>
-          <?php print $feed_icons ?>
-          <div id="footer"><?php //print $footer_message . $footer ?></div>
-      </div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->
-
-    </div> <!-- /container -->
-
-<!-- /layout -->
-
-  <?php print $closure ?>
-  </body>
-</html>
+  /**
+   * @file
+   * Display the widget in an iFrame.
+   */
+?>
+<div id="widget-wrapper"><div id="widget">
+  <div class="element-invisible">
+    <?php print render($page['page_top']); ?>
+  </div>
+
+  <?php if ($messages): ?>
+    <div id="messages"><div class="section clearfix">
+      <?php print $messages; ?>
+    </div></div> <!-- /.section, /#messages -->
+  <?php endif; ?>
+
+  <div id="main-wrapper" class="clearfix"><div id="main" class="clearfix">
+
+    <div id="content" class="column"><div class="section">
+      <a id="main-content"></a>
+      <?php print render($title_prefix); ?>
+      <?php if ($title): ?>
+        <h2 id="title">
+          <?php print $title; ?>
+        </h1>
+      <?php endif; ?>
+      <?php print render($title_suffix); ?>
+      <?php if ($tabs): ?>
+        <div class="tabs">
+          <?php print render($tabs); ?>
+        </div>
+      <?php endif; ?>
+      <?php print render($page['help']); ?>
+
+      <?php print embed_widgets_alter_links(render($page['content'])); ?>
+      <?php print $feed_icons; ?>
+
+    </div></div> <!-- /.section, /#content -->
+
+  </div></div> <!-- /#main, /#main-wrapper -->
+    <?php if (isset($back_to_widget)): ?>
+      <div id="back-container">
+        <?php print l(t('Back'), $widget_url); ?>
+      </div>
+    <?php else: ?>
+      <div id="share-container">
+        <?php print $share_widget ?>
+      </div>
+    <?php endif; ?>
+
+  <div class="element-invisible">
+    <?php print render($page['page_bottom']); ?>
+  </div>
+
+</div></div> <!-- /#page, /#page-wrapper -->
