diff --git a/panels_ipe/js/panels_ipe.js b/panels_ipe/js/panels_ipe.js
index ec34780..3c417a4 100644
--- a/panels_ipe/js/panels_ipe.js
+++ b/panels_ipe/js/panels_ipe.js
@@ -93,7 +93,7 @@ function DrupalPanelsIPE(cache_key, cfg) {
   });
 
   // If a user navigates away from a locked IPE, cancel the lock in the background.
-  $(window).bind('unload', function() {
+  $(window).bind('beforeunload', function() {
     ipe.cancelLock(true);
   });
 
diff --git a/panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php b/panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php
index aedc913..984ee83 100644
--- a/panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php
+++ b/panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php
@@ -209,8 +209,9 @@ class panels_renderer_ipe extends panels_renderer_editor {
    * now in a 'normal' state.
    */
   function ajax_unlock_ipe() {
-    panels_edit_cache_clear($this->cache);
     $this->commands[] = array();
+    $this->cache->ipe_locked = NULL;
+    panels_edit_cache_set($this->cache);
   }
 
   /**
@@ -244,7 +245,7 @@ class panels_renderer_ipe extends panels_renderer_editor {
         'command' => 'initIPE',
         'key' => $this->clean_key,
         'data' => drupal_render($output),
-        'lockPath' => $this->get_url('unlock_ipe'),
+        'lockPath' => base_path() . $this->get_url('unlock_ipe'),
       );
       return;
     }
@@ -270,8 +271,9 @@ class panels_renderer_ipe extends panels_renderer_editor {
       $this->commands[] = ajax_command_replace("#panels-ipe-display-{$this->clean_key}", panels_render_display($this->display, $this));
     }
     else {
-      // Cancelled. Clear the cache.
-      panels_edit_cache_clear($this->cache);
+      // Cancelled. Release the lock.
+      $this->cache->ipe_locked = NULL;
+      panels_edit_cache_set($this->cache);
     }
 
     $this->commands[] = array(
@@ -315,7 +317,7 @@ class panels_renderer_ipe extends panels_renderer_editor {
     $this->commands[] = array(
       'command' => 'IPEsetLockState',
       'key' => $this->clean_key,
-      'lockPath' => $this->get_url('unlock_ipe'),
+      'lockPath' => base_path() . $this->get_url('unlock_ipe'),
     );
   }
 
@@ -344,6 +346,7 @@ class panels_renderer_ipe extends panels_renderer_editor {
       if (!empty($form_state['clicked_button']['#save-display'])) {
         // Saved. Save the cache.
         panels_edit_cache_save($this->cache);
+        panels_edit_cache_set($this->cache);
         $this->display->skip_cache;
 
         // Since the layout changed, we have to update these things in the
