diff --git a/build/index.php b/build/index.php
index ae5b4e1..8f733d1 100644
--- a/build/index.php
+++ b/build/index.php
@@ -1488,7 +1488,6 @@ class search
 		
 		$index = [];
 		
-		// Regex from 
 		$terms = self::tokenize($source);
 		$i = 0;
 		foreach($terms as $term)
@@ -1559,14 +1558,18 @@ class search
 	 * @param {array} $removed - An array to be filled with the nterms of all
 	 * 							 the removed entries.
 	 */
-	public static function compare_indexes($indexa, $indexb, &$changed, &$removed)
+	public static function compare_indexes($oldindex, $newindex, &$changed, &$removed)
 	{
-		foreach ($indexa as $nterm => $entrya)
+		foreach($oldindex as $nterm => $entry)
 		{
-			if(!isset($indexb[$nterm]))
+			if(!isset($newindex[$nterm]))
 				$removed[] = $nterm;
-			$entryb = $indexb[$nterm];
-			if($entrya !== $entryb) $changed[] = $nterm;
+		}
+		foreach($newindex as $nterm => $entry)
+		{
+			if(!isset($oldindex[$nterm]) or // If this world is new
+			   $newindex[$nterm] !== $oldindex[$nterm]) // If this word has changed
+				$changed[$nterm] = $newindex[$nterm];
 		}
 	}
 	
@@ -1603,6 +1606,13 @@ class search
 				return ($a["freq"] < $b["freq"]) ? +1 : -1;
 			});
 		}
+		
+		// Sort the inverted index by rank
+		uasort($invindex, function($a, $b) {
+			$ac = count($a); $bc = count($b);
+			if($ac == $bc) return 0;
+			return ($ac < $bc) ? +1 : -1;
+		});
 	}
 	
 	public static function save_invindex($filename, &$invindex)
@@ -2284,7 +2294,7 @@ register_module([
 			}
 			
 			$content = "<h1>$title</h1>";
-			$page_tags = implode(", ", (!empty($pageindex->{$env->page}->tags)) ? $pageindex->{$env->page}->tags : [ "" ]);
+			$page_tags = implode(", ", (!empty($pageindex->{$env->page}->tags)) ? $pageindex->{$env->page}->tags : []);
 			if(!$env->is_logged_in and $settings->anonedits)
 			{
 				$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
@@ -2361,6 +2371,12 @@ register_module([
 			// Construct an index for the old and new page content
 			$oldindex = search::index(file_get_contents("$env->page.md"));
 			$newindex = search::index($pagedata);
+			
+			echo("old: ");
+			var_dump($oldindex);
+			echo("new: ");
+			var_dump($newindex);
+			
 			// Compare the indexes of the old and new content
 			$additions = [];
 			$removals = [];
@@ -2416,13 +2432,14 @@ register_module([
 				else
 					http_response_code(200);
 				
+//				header("content-type: text/plain");
 				header("location: index.php?page=$env->page&edit_status=success&redirect=no");
 				exit();
 			}
 			else
 			{
 				http_response_code(507);
-				exit(page_renderer::render_main("Error saving page - $settings->sitename", "<p>$settings->sitename failed to write your changes to the disk. Your changes have not been saved, but you might be able to recover your edit by pressing the back button in your browser.</p>
+				exit(page_renderer::render_main("Error saving page - $settings->sitename", "<p>$settings->sitename failed to write your changes to the server's disk. Your changes have not been saved, but you might be able to recover your edit by pressing the back button in your browser.</p>
 				<p>Please tell the administrator of this wiki (" . $settings->admindetails["name"] . ") about this problem.</p>"));
 			}
 		});
diff --git a/module_index.json b/module_index.json
index 29cff1b..24bc6f2 100644
--- a/module_index.json
+++ b/module_index.json
@@ -50,7 +50,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.",
         "id": "feature-search",
-        "lastupdate": 1446372585,
+        "lastupdate": 1446387843,
         "optional": false
     },
     {
@@ -86,7 +86,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
         "id": "page-edit",
-        "lastupdate": 1446314649,
+        "lastupdate": 1446387938,
         "optional": false
     },
     {
diff --git a/modules/feature-search.php b/modules/feature-search.php
index ea1fcd6..7540c30 100644
--- a/modules/feature-search.php
+++ b/modules/feature-search.php
@@ -144,7 +144,6 @@ class search
 		
 		$index = [];
 		
-		// Regex from 
 		$terms = self::tokenize($source);
 		$i = 0;
 		foreach($terms as $term)
@@ -215,14 +214,18 @@ class search
 	 * @param {array} $removed - An array to be filled with the nterms of all
 	 * 							 the removed entries.
 	 */
-	public static function compare_indexes($indexa, $indexb, &$changed, &$removed)
+	public static function compare_indexes($oldindex, $newindex, &$changed, &$removed)
 	{
-		foreach ($indexa as $nterm => $entrya)
+		foreach($oldindex as $nterm => $entry)
 		{
-			if(!isset($indexb[$nterm]))
+			if(!isset($newindex[$nterm]))
 				$removed[] = $nterm;
-			$entryb = $indexb[$nterm];
-			if($entrya !== $entryb) $changed[] = $nterm;
+		}
+		foreach($newindex as $nterm => $entry)
+		{
+			if(!isset($oldindex[$nterm]) or // If this world is new
+			   $newindex[$nterm] !== $oldindex[$nterm]) // If this word has changed
+				$changed[$nterm] = $newindex[$nterm];
 		}
 	}
 	
@@ -259,6 +262,13 @@ class search
 				return ($a["freq"] < $b["freq"]) ? +1 : -1;
 			});
 		}
+		
+		// Sort the inverted index by rank
+		uasort($invindex, function($a, $b) {
+			$ac = count($a); $bc = count($b);
+			if($ac == $bc) return 0;
+			return ($ac < $bc) ? +1 : -1;
+		});
 	}
 	
 	public static function save_invindex($filename, &$invindex)
diff --git a/modules/page-edit.php b/modules/page-edit.php
index 635297e..6ed9c5a 100644
--- a/modules/page-edit.php
+++ b/modules/page-edit.php
@@ -137,6 +137,12 @@ register_module([
 			// Construct an index for the old and new page content
 			$oldindex = search::index(file_get_contents("$env->page.md"));
 			$newindex = search::index($pagedata);
+			
+			echo("old: ");
+			var_dump($oldindex);
+			echo("new: ");
+			var_dump($newindex);
+			
 			// Compare the indexes of the old and new content
 			$additions = [];
 			$removals = [];
@@ -192,13 +198,14 @@ register_module([
 				else
 					http_response_code(200);
 				
+//				header("content-type: text/plain");
 				header("location: index.php?page=$env->page&edit_status=success&redirect=no");
 				exit();
 			}
 			else
 			{
 				http_response_code(507);
-				exit(page_renderer::render_main("Error saving page - $settings->sitename", "<p>$settings->sitename failed to write your changes to the disk. Your changes have not been saved, but you might be able to recover your edit by pressing the back button in your browser.</p>
+				exit(page_renderer::render_main("Error saving page - $settings->sitename", "<p>$settings->sitename failed to write your changes to the server's disk. Your changes have not been saved, but you might be able to recover your edit by pressing the back button in your browser.</p>
 				<p>Please tell the administrator of this wiki (" . $settings->admindetails["name"] . ") about this problem.</p>"));
 			}
 		});
