diff --git a/html--modalframe.tpl.php b/html--modalframe.tpl.php
new file mode 100644
index 0000000..2bf80c4
--- /dev/null
+++ b/html--modalframe.tpl.php
@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>"
+  <?php print $rdf_namespaces; ?>>
+
+<head profile="<?php print $grddl_profile; ?>">
+  <?php print $head; ?>
+  <title><?php print $head_title; ?></title>
+  <?php print $styles; ?>
+  <?php print $scripts; ?>
+</head>
+<body class="<?php print $classes; ?>" <?php print $attributes;?>>
+  <div id="skip">
+    <a href="#main-menu"><?php print t('Jump to Navigation'); ?></a>
+  </div>
+  <?php print $page_top; ?>
+  <?php print $page; ?>
+  <?php print $page_bottom; ?>
+</body>
+</html>
diff --git a/js/child.js b/js/child.js
index 4421b16..f76361f 100644
--- a/js/child.js
+++ b/js/child.js
@@ -120,6 +120,9 @@ Drupal.modalFrameChild.behaviors.parseLinks = function(context) {
  * problems with other behaviors that need the document visible in order to
  * do its own job.
  */
-Drupal.behaviors = $.extend({modalFrameChild: Drupal.modalFrameChild.attach}, Drupal.behaviors);
+  Drupal.behaviors.modalFrameChild = {};
+  Drupal.behaviors.modalFrameChild.attach = function (context, settings) {
+    Drupal.modalFrameChild.attach(context);
+  }
 
 })(jQuery);
diff --git a/modalframe-page.tpl.php b/modalframe-page.tpl.php
deleted file mode 100644
index c98c46f..0000000
--- a/modalframe-page.tpl.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-/**
- * @file
- * Template file for a Modal Frame based on jQuery UI dialog.
- *
- * This template provides the same exact variables provided to page.tpl.php,
- * and serves the same purpose, with the exeption that this template does not
- * render regions such as head, left and right because the main purpose of this
- * template is to render a frame that is displayed on a modal jQuery UI dialog.
- *
- * @see modalframe_theme_registry_alter()
- * @see modalframe_preprocess_page()
- * @see template_preprocess_page()
- * @see template_preprocess()
- * @see theme()
- */
-
-?><!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>
-<?php print $head; ?>
-<title><?php print (!empty($title) ? strip_tags($title) : $head_title); ?></title>
-<?php print $styles; ?>
-<?php print $scripts; ?>
-</head>
-<body>
-<div class="modalframe-page-wrapper">
-  <div class="modalframe-page-container clear-block">
-    <div class="modalframe-page-content">
-<?php if ($show_messages && $messages): print $messages; endif; ?>
-<?php print $help; ?>
-<div class="clear-block">
-  <?php print $content; ?>
-</div>
-    </div>
-  </div>
-</div>
-<?php print $closure; ?>
-</body>
-</html>
diff --git a/modalframe.info b/modalframe.info
index b1b4ead..51e05c9 100644
--- a/modalframe.info
+++ b/modalframe.info
@@ -1,5 +1,4 @@
 name = Modal Frame API
 description = Provides an API to render an iframe within a modal dialog based on the jQuery UI Dialog plugin.
 package = Modal frame
-dependencies[] = jquery_ui
-core = 6.x
+core = 7.x
diff --git a/modalframe.install b/modalframe.install
deleted file mode 100644
index 8026840..0000000
--- a/modalframe.install
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-/**
- * @file
- * Installation file for Modal Frame API module.
- */
-
-/**
- * Implementation of hook_requirements().
- */
-function modalframe_requirements($phase) {
-  $requirements = array();
-  $t = get_t();
-  drupal_load('module', 'jquery_ui');
-  $jquery_ui_version = function_exists('jquery_ui_get_version') ? jquery_ui_get_version() : 0;
-
-  if (version_compare($jquery_ui_version, '1.7') < 0) {
-    $requirements['modalframe'] = array(
-      'title' => $t('Modal Frame API'),
-      'value' => $jquery_ui_version,
-      'severity' => ($phase == 'runtime' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR),
-      'description' => $t('The version of the <a href="@jqueryui">jQuery UI</a> library installed on this site is not compatible with <a href="@modalframe">Modal Frame API</a>. Please, upgrade to jQuery UI 1.7.x or higher.', array(
-        '@jqueryui' => 'http://drupal.org/project/jquery_ui',
-        '@modalframe' => 'http://drupal.org/project/modalframe',
-      )),
-    );
-  }
-
-  return $requirements;
-}
diff --git a/modalframe.module b/modalframe.module
index 3f044c6..3bf045f 100644
--- a/modalframe.module
+++ b/modalframe.module
@@ -49,14 +49,39 @@
  * @ingroup themeable
  */
 function modalframe_theme_registry_alter(&$theme_registry) {
-  if (isset($theme_registry['page']) && isset($theme_registry['page']['theme paths'])) {
+  if (isset($theme_registry['page'])) {
+    $theme_registry['page']['theme paths'] = array();
     $module_path = drupal_get_path('module', 'modalframe');
-    array_unshift($theme_registry['page']['theme paths'], $module_path);
+    $theme = list_themes();
+    $theme_registry_copy = $theme_registry;       // munge on a copy
+    _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'pow', $module_path);
+    $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
+    $hooks = array('page', 'html');
+    foreach ($hooks as $h) {
+      _modalframe_insert_after_first_element($theme_registry[$h]['theme paths'], $module_path);
+    }
+
+    // Add pre-preprocess function for page template.
     array_unshift($theme_registry['page']['preprocess functions'], 'modalframe_pre_preprocess_page');
   }
 }
 
 /**
+ * Helper function for modalframe_theme_registry_alter()
+ *
+ * Alters order of elements in theme paths array.
+ *
+ * @param array $a
+ * @param array $element
+ */
+function _modalframe_insert_after_first_element(&$a, $element) {
+  if(is_array($a)) {
+    $first_element = array_shift($a);
+    array_unshift($a, $first_element, $element);
+  }
+}
+
+/**
  * Preprocess template variables for page.tpl.php - step 1.
  *
  * Performance enhancement: prevent template_preprocess_page() from generating
@@ -69,6 +94,15 @@ function modalframe_pre_preprocess_page(&$variables) {
 }
 
 /**
+ * Preprocess template variables for html.tpl.php
+ */
+function modalframe_preprocess_html(&$variables) {
+  if (!empty($GLOBALS['modalframe_page_template'])) {
+    $variables['theme_hook_suggestions'][] = 'html__modalframe';
+  }
+}
+
+/**
  * Preprocess template variables for page.tpl.php - step 2.
  *
  * Now that we have altered the registry entry for theme('page'), we can tell
@@ -85,10 +119,7 @@ function modalframe_pre_preprocess_page(&$variables) {
  */
 function modalframe_preprocess_page(&$variables) {
   if (!empty($GLOBALS['modalframe_page_template'])) {
-    if (!isset($variables['template_files'])) {
-      $variables['template_files'] = array();
-    }
-    $variables['template_files'][] = 'modalframe-page';
+    $variables['theme_hook_suggestions'][] = 'page__modalframe';
   }
 }
 
@@ -125,7 +156,7 @@ function modalframe_preprocess_page(&$variables) {
  *
  * @ingroup forms
  */
-function modalframe_form_alter(&$form, $form_state, $form_id) {
+function modalframe_form_alter(&$form, &$form_state, $form_id) {
   // Here we simply want to install a form after_build callback.
   if (!isset($form['#after_build'])) {
     $form['#after_build'] = array();
@@ -217,7 +248,8 @@ function modalframe_parent_js() {
   }
   $processed = TRUE;
 
-  jquery_ui_add(array('ui.dialog', 'ui.draggable'));
+  drupal_add_library('system', 'ui.dialog');
+  drupal_add_library('system', 'ui.draggable');
   $module_path = drupal_get_path('module', 'modalframe');
   drupal_add_css($module_path .'/css/modalframe.parent.css');
   drupal_add_js($module_path .'/js/parent.js');
@@ -240,10 +272,6 @@ function modalframe_child_js() {
   // is something child windows don't need.
   module_invoke_all('suppress');
 
-  // This is required to get access to jQuery UI extensions to jQuery itself,
-  // such as the ':focusable' and ':tabbable' selectors.
-  jquery_ui_add(array('ui.core'));
-
   // Add javascript and stylesheets to the child page.
   $module_path = drupal_get_path('module', 'modalframe');
   drupal_add_css($module_path .'/css/modalframe.child.css');
diff --git a/modules/modalframe_example/modalframe_example.info b/modules/modalframe_example/modalframe_example.info
index a70b5be..8ab801a 100644
--- a/modules/modalframe_example/modalframe_example.info
+++ b/modules/modalframe_example/modalframe_example.info
@@ -2,4 +2,4 @@ name = Modal Frame Example
 description = Example for the Modal Frame API.
 package = Modal frame
 dependencies[] = modalframe
-core = 6.x
+core = 7.x
diff --git a/modules/modalframe_example/modalframe_example.js b/modules/modalframe_example/modalframe_example.js
index e0ea740..d822b44 100644
--- a/modules/modalframe_example/modalframe_example.js
+++ b/modules/modalframe_example/modalframe_example.js
@@ -1,49 +1,51 @@
 
 (function ($) {
 
-Drupal.behaviors.modalFrameExample = function() {
-  $('.modalframe-example-child:not(.modalframe-example-processed)').addClass('modalframe-example-processed').click(function() {
-    var element = this;
-
-    // This is our onSubmit callback that will be called from the child window
-    // when it is requested by a call to modalframe_close_dialog() performed
-    // from server-side submit handlers.
-    function onSubmitCallbackExample(args, statusMessages) {
-      // Display status messages generated during submit processing.
-      if (statusMessages) {
-        $('.modalframe-example-messages').hide().html(statusMessages).show('slow');
+Drupal.behaviors.modalFrameExample = {
+  attach: function() {
+    $('.modalframe-example-child:not(.modalframe-example-processed)').addClass('modalframe-example-processed').click(function() {
+      var element = this;
+  
+      // This is our onSubmit callback that will be called from the child window
+      // when it is requested by a call to modalframe_close_dialog() performed
+      // from server-side submit handlers.
+      function onSubmitCallbackExample(args, statusMessages) {
+        // Display status messages generated during submit processing.
+        if (statusMessages) {
+          $('.modalframe-example-messages').hide().html(statusMessages).show('slow');
+        }
+  
+        if (args && args.message) {
+          // Provide a simple feedback alert deferred a little.
+          setTimeout(function() { alert(args.message); }, 500);
+        }
       }
-
-      if (args && args.message) {
-        // Provide a simple feedback alert deferred a little.
-        setTimeout(function() { alert(args.message); }, 500);
+  
+      // Hide the messages are before opening a new dialog.
+      $('.modalframe-example-messages').hide('fast');
+  
+      // Build modal frame options.
+      var modalOptions = {
+        url: $(element).attr('href'),
+        autoFit: true,
+        onSubmit: onSubmitCallbackExample
+      };
+  
+      // Try to obtain the dialog size from the className of the element.
+      var regExp = /^.*modalframe-example-size\[\s*([0-9]*\s*,\s*[0-9]*)\s*\].*$/;
+      if (typeof element.className == 'string' && regExp.test(element.className)) {
+        var size = element.className.replace(regExp, '$1').split(',');
+        modalOptions.width = parseInt(size[0].replace(/ /g, ''));
+        modalOptions.height = parseInt(size[1].replace(/ /g, ''));
       }
-    }
-
-    // Hide the messages are before opening a new dialog.
-    $('.modalframe-example-messages').hide('fast');
-
-    // Build modal frame options.
-    var modalOptions = {
-      url: $(element).attr('href'),
-      autoFit: true,
-      onSubmit: onSubmitCallbackExample
-    };
-
-    // Try to obtain the dialog size from the className of the element.
-    var regExp = /^.*modalframe-example-size\[\s*([0-9]*\s*,\s*[0-9]*)\s*\].*$/;
-    if (typeof element.className == 'string' && regExp.test(element.className)) {
-      var size = element.className.replace(regExp, '$1').split(',');
-      modalOptions.width = parseInt(size[0].replace(/ /g, ''));
-      modalOptions.height = parseInt(size[1].replace(/ /g, ''));
-    }
-
-    // Open the modal frame dialog.
-    Drupal.modalFrame.open(modalOptions);
-
-    // Prevent default action of the link click event.
-    return false;
-  });
+  
+      // Open the modal frame dialog.
+      Drupal.modalFrame.open(modalOptions);
+  
+      // Prevent default action of the link click event.
+      return false;
+    });
+  }
 };
 
 })(jQuery);
diff --git a/modules/modalframe_example/modalframe_example.module b/modules/modalframe_example/modalframe_example.module
index 4fe2fd4..c7c7ee0 100644
--- a/modules/modalframe_example/modalframe_example.module
+++ b/modules/modalframe_example/modalframe_example.module
@@ -8,8 +8,14 @@
 /**
  * Implementation of hook_perm().
  */
-function modalframe_example_perm() {
-  return array('access modalframe examples');
+function modalframe_example_permission() {
+  $permissions = array(
+    'access modalframe examples' => array(
+      'title' => t('access modalframe examples'),
+    	'description' => t('Collection of examples using modalframe.')
+    )
+  );
+  return $permissions;
 }
 
 /**
@@ -22,7 +28,7 @@ function modalframe_example_menu() {
     'title' => 'Modal Frame Examples',
     'page callback' => 'modalframe_example_page',
     'access arguments' => array('access modalframe examples'),
-    'type' => MENU_NORMAL_ITEM,
+  	'type' => MENU_NORMAL_ITEM,
   );
 
   // Hello world example.
@@ -77,8 +83,7 @@ function modalframe_example_page() {
     modalframe_example_get_item(t('Simple form where menu callback is a custom function'), 'modalframe-example/simple-page/first/second/third', '350,400'),
     modalframe_example_get_item(t('Custom menu callback to edit a node'), 'modalframe-example/node-edit'),
   );
-  $output .= theme('item_list', $items);
-
+  $output .= theme('item_list', array('items' => $items));
   return $output;
 }
 
@@ -112,8 +117,8 @@ function modalframe_example_simple_page($first = NULL, $second = NULL, $third =
 /**
  * Generate the form for the child window.
  */
-function modalframe_example_simple_form(&$form_state) {
-  $form = array();
+function modalframe_example_simple_form($form, &$form_state) {
+	$form = array();
 
   // Send the Modal Frame javascript for child windows to the page.
   modalframe_child_js();
@@ -162,8 +167,11 @@ function modalframe_example_node_edit_page() {
   modalframe_child_js();
 
   // Let's find the last created node the current user has edit access to.
-  $nid = (int)db_result(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n ORDER BY n.nid DESC'), 0, 1));
+//   $nid = (int)db_result(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n ORDER BY n.nid DESC'), 0, 1));
+  $nid = db_query('SELECT n.nid FROM {node} n ORDER BY n.nid DESC')->fetchField();
+
   $node = node_load($nid);
+  
   if (!$node || !node_access('update', $node)) {
     drupal_set_message(t('Sorry, could not find any node that you are allowed to edit for this test.'), 'error');
     drupal_not_found();
@@ -179,7 +187,8 @@ function modalframe_example_node_edit_page() {
 
   // Render the node edit form itself.
   module_load_include('inc', 'node', 'node.pages');
-  $output .= node_page_edit($node);
+  $node_edit_form = node_page_edit($node);
+  $output .= drupal_render($node_edit_form);
 
   return $output;
 }
@@ -208,15 +217,17 @@ function modalframe_example_form_alter(&$form, $form_state, $form_id) {
       // where we may wish to close the modal frame dialog.
       // So let's keep this as simple as possible. We are now hidding all
       // buttons, except "Save" and "Preview".
-      foreach (element_children($form['buttons']) as $key) {
-        if (!in_array($key, array('submit', 'preview')) && isset($form['buttons'][$key]) && $form['buttons'][$key]) {
-          unset($form['buttons'][$key]);
+      foreach (element_children($form['actions']) as $key) {
+        if (!in_array($key, array('submit', 'preview')) && isset($form['actions'][$key]) && $form['actions'][$key]) {
+          unset($form['actions'][$key]);
+        }
+        if ($key == 'submit') {
+          // Append our submit handler. This is required if we want a chance to
+          // close the modal frame dialog. Submit handler must be attached 
+          // directly to submit button to work with node edit field. 
+          $form['actions'][$key]['#submit'][] = 'modalframe_example_form_submit';
         }
       }
-
-      // Append our submit handler. This is required if we want a chance to
-      // close the modal frame dialog.
-      $form['#submit'][] = 'modalframe_example_form_submit';
     }
   }
 }
@@ -231,7 +242,10 @@ function modalframe_example_form_alter(&$form, $form_state, $form_id) {
  */
 function modalframe_example_form_submit($form, &$form_state) {
   // Ignore preview requests. Close dialog only when user clicks "Save" button.
-  if ($form_state['values']['op'] == t('Save')) {
+  if ($form_state['triggering_element']['#value'] == t('Save')) {
+    // Disable form redirection. Required to ensure modelframe_close_dialog
+    // will function correctly with node edit form.
+    $form_state['redirect'] = FALSE;  
     // Tell the parent window to close the modal frame dialog.
     modalframe_close_dialog(array(
       'message' => t('This is an argument sent by the Modal Frame API from the submit handler attached to the node edit form!'),
diff --git a/page--modalframe.tpl.php b/page--modalframe.tpl.php
new file mode 100644
index 0000000..0e95f42
--- /dev/null
+++ b/page--modalframe.tpl.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * @file
+ * Template file for a page rebdered in Modal Frame based on jQuery UI dialog.
+ *
+ * This template provides the same exact variables provided to page.tpl.php,
+ * and serves the same purpose, with the exeption that this template does not
+ * render regions such as head, left and right because the main purpose of this
+ * template is to render a frame that is displayed on a modal jQuery UI dialog.
+ *
+ * @see modalframe_theme_registry_alter()
+ * @see modalframe_preprocess_page()
+ * @see template_preprocess_page()
+ * @see template_preprocess()
+ * @see theme()
+ */
+?>
+<div class="modalframe-page-wrapper">
+  <div class="modalframe-page-container clear-block">
+    <div class="modalframe-page-content">
+      <?php print $messages; ?>
+      <?php print render($page['help']); ?>
+      <div class="clear-block">
+        <?php print render($page['content']); ?>
+      </div>
+    </div>
+  </div>
+</div>
