4735a4
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
4735a4
index e97fe283..7d8f2395 100644
4735a4
--- a/src/dh-book-tree.c
4735a4
+++ b/src/dh-book-tree.c
4735a4
@@ -177,7 +177,7 @@ book_tree_find_language_group (DhBookTree  *tree,
4735a4
                         g_return_if_reached ();
4735a4
                 }
4735a4
 
4735a4
-                if (exact_iter != NULL &&
4735a4
+                if (exact_iter != NULL && exact_found &&
4735a4
                     g_ascii_strcasecmp (title, language) == 0) {
4735a4
                         /* Exact match found! */
4735a4
                         *exact_iter = loop_iter;
4735a4
@@ -187,7 +187,7 @@ book_tree_find_language_group (DhBookTree  *tree,
4735a4
                                 g_free (title);
4735a4
                                 return;
4735a4
                         }
4735a4
-                } else if (next_iter != NULL &&
4735a4
+                } else if (next_iter != NULL && next_found &&
4735a4
                            g_ascii_strcasecmp (title, language) > 0) {
4735a4
                         *next_iter = loop_iter;
4735a4
                         *next_found = TRUE;
4735a4
@@ -252,7 +252,7 @@ book_tree_find_book (DhBookTree        *tree,
4735a4
 
4735a4
                 /* We can compare pointers directly as we're playing with references
4735a4
                  * of the same object */
4735a4
-                if (exact_iter != NULL &&
4735a4
+                if (exact_iter != NULL && exact_found &&
4735a4
                     in_tree_book == book) {
4735a4
                         *exact_iter = loop_iter;
4735a4
                         *exact_found = TRUE;
4735a4
diff --git a/src/dh-keyword-model.c b/src/dh-keyword-model.c
4735a4
index a0b716f4..6a7fc50d 100644
4735a4
--- a/src/dh-keyword-model.c
4735a4
+++ b/src/dh-keyword-model.c
4735a4
@@ -442,6 +442,14 @@ search_single_book (DhBook          *book,
4735a4
         return ret;
4735a4
 }
4735a4
 
4735a4
+static gint
4735a4
+compare_links (gconstpointer a,
4735a4
+               gconstpointer b,
4735a4
+               gpointer user_data)
4735a4
+{
4735a4
+        return dh_link_compare (a, b);
4735a4
+}
4735a4
+
4735a4
 static GQueue *
4735a4
 search_books (SearchSettings  *settings,
4735a4
               guint            max_hits,
4735a4
@@ -486,7 +494,7 @@ search_books (SearchSettings  *settings,
4735a4
                 dh_util_queue_concat (ret, book_result);
4735a4
         }
4735a4
 
4735a4
-        g_queue_sort (ret, (GCompareDataFunc) dh_link_compare, NULL);
4735a4
+        g_queue_sort (ret, (GCompareDataFunc) compare_links, NULL);
4735a4
         return ret;
4735a4
 }
4735a4
 
4735a4
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
4735a4
index 0568c505..ffae33b3 100644
4735a4
--- a/src/dh-preferences.c
4735a4
+++ b/src/dh-preferences.c
4735a4
@@ -143,7 +143,7 @@ preferences_bookshelf_find_book (DhPreferences     *prefs,
4735a4
                                     -1);
4735a4
 
4735a4
                 /* We may have reached the start of the next language group here */
4735a4
-                if (first && !in_list_book) {
4735a4
+                if (exact_found && first && !in_list_book) {
4735a4
                         *next_iter = loop_iter;
4735a4
                         *next_found = TRUE;
4735a4
                         return;
4735a4
@@ -151,7 +151,7 @@ preferences_bookshelf_find_book (DhPreferences     *prefs,
4735a4
 
4735a4
                 /* We can compare pointers directly as we're playing with references
4735a4
                  * of the same object */
4735a4
-                if (exact_iter &&
4735a4
+                if (exact_iter && exact_found &&
4735a4
                     in_list_book == book) {
4735a4
                         *exact_iter = loop_iter;
4735a4
                         *exact_found = TRUE;
4735a4
@@ -160,7 +160,7 @@ preferences_bookshelf_find_book (DhPreferences     *prefs,
4735a4
                                 g_object_unref (in_list_book);
4735a4
                                 return;
4735a4
                         }
4735a4
-                } else if (next_iter &&
4735a4
+                } else if (next_iter && next_found &&
4735a4
                            dh_book_cmp_by_title (in_list_book, book) > 0) {
4735a4
                         *next_iter = loop_iter;
4735a4
                         *next_found = TRUE;
4735a4
@@ -223,7 +223,7 @@ preferences_bookshelf_find_language_group (DhPreferences *prefs,
4735a4
                         continue;
4735a4
                 }
4735a4
 
4735a4
-                if (exact_iter &&
4735a4
+                if (exact_iter && exact_found &&
4735a4
                     g_ascii_strcasecmp (title, language) == 0) {
4735a4
                         /* Exact match found! */
4735a4
                         *exact_iter = loop_iter;
4735a4
@@ -233,7 +233,7 @@ preferences_bookshelf_find_language_group (DhPreferences *prefs,
4735a4
                                 g_free (title);
4735a4
                                 return;
4735a4
                         }
4735a4
-                } else if (next_iter &&
4735a4
+                } else if (next_iter && next_found &&
4735a4
                            g_ascii_strcasecmp (title, language) > 0) {
4735a4
                         *next_iter = loop_iter;
4735a4
                         *next_found = TRUE;