diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 1b42b62..41be31e 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -41,6 +41,7 @@
 #include <string.h>
 
 #define EPHY_LOCATION_ENTRY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_LOCATION_ENTRY, EphyLocationEntryPrivate))
+#define MAX_MATCHES 40
 
 struct _EphyLocationEntryPrivate
 {
@@ -76,6 +77,9 @@ struct _EphyLocationEntryPrivate
 	guint secure : 1;
 	guint apply_colours : 1;
 	guint needs_reset : 1;
+
+	gint matches_count;
+	gboolean (* match_func) (GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer user_data);
 };
 
 static const GtkTargetEntry url_drag_types [] =
@@ -365,6 +369,9 @@ editable_changed_cb (GtkEditable *editable,
 				G_REGEX_CASELESS | G_REGEX_OPTIMIZE, 
 				G_REGEX_MATCH_NOTEMPTY, NULL);
 
+	if (priv->matches_count > MAX_MATCHES)
+		priv->matches_count = 0;
+
 	g_free (pattern);
 
 	update_favicon (entry);
@@ -923,6 +930,7 @@ ephy_location_entry_init (EphyLocationEntry *le)
 	p->block_update = FALSE;
 	p->saved_text = NULL;
 	p->regex = NULL;
+	p->matches_count = 0;
 	
 	ephy_location_entry_construct_contents (le);
 
@@ -986,6 +994,27 @@ extracell_data_func (GtkCellLayout *cell_layout,
 	g_value_unset (&visible);
 }
 
+
+static gboolean
+match_func_wrapper (GtkEntryCompletion *completion,
+		const char *key,
+		GtkTreeIter *iter,
+		gpointer data)
+{
+	gboolean ret;
+	EphyLocationEntryPrivate *priv = ((EphyLocationEntry *) data)->priv;
+
+	if (priv->matches_count > MAX_MATCHES)
+		return FALSE;
+
+	ret = priv->match_func(completion, key, iter, data);
+
+	if (ret && priv->matches_count <= MAX_MATCHES)
+		priv->matches_count++;
+
+	return ret;
+}
+
 void
 ephy_location_entry_set_match_func (EphyLocationEntry *le, 
 				GtkEntryCompletionMatchFunc match_func,
@@ -996,7 +1025,11 @@ ephy_location_entry_set_match_func (EphyLocationEntry *le,
 	GtkEntryCompletion *completion;
 	
 	completion = gtk_entry_get_completion (GTK_ENTRY (priv->icon_entry->entry));
-	gtk_entry_completion_set_match_func (completion, match_func, user_data, notify);
+	priv->match_func = match_func;
+	gtk_entry_completion_set_match_func (completion,
+			match_func_wrapper,
+			le,
+			notify);
 }
 
 void
diff --git a/src/ephy-location-action.c b/src/ephy-location-action.c
index 2c1f944..de2bc00 100644
--- a/src/ephy-location-action.c
+++ b/src/ephy-location-action.c
@@ -85,18 +85,6 @@ static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE (EphyLocationAction, ephy_location_action, EPHY_TYPE_LINK_ACTION)
 
-typedef struct
-{
-	EphyLocationEntry *entry;
-	EphyLocationAction *action;
-} LocationEntryAction;
-
-static void
-destroy_match_func (gpointer data)
-{
-	g_slice_free (LocationEntryAction, data);
-}
-
 static gboolean
 match_func (GtkEntryCompletion *completion,
 		const char *key,
@@ -109,12 +97,9 @@ match_func (GtkEntryCompletion *completion,
 	char *extra = NULL;
 
 	gboolean ret = FALSE;
-	EphyLocationActionPrivate *priv;
 	GtkTreeModel *model;
 	GRegex *regex;
 
-	priv = EPHY_LOCATION_ACTION (((LocationEntryAction *) data)->action)->priv;
-
 	model = gtk_entry_completion_get_model (completion);
 
 	gtk_tree_model_get (model, iter,
@@ -127,7 +112,7 @@ match_func (GtkEntryCompletion *completion,
 	if (!key)
 		return FALSE;
 	
-	regex = ephy_location_entry_get_regex (((LocationEntryAction *) data)->entry);
+	regex = ephy_location_entry_get_regex ((EphyLocationEntry *) data);
 	
 	ret = (g_regex_match (regex, item, G_REGEX_MATCH_NOTEMPTY, NULL)
 		|| g_regex_match (regex, url, G_REGEX_MATCH_NOTEMPTY, NULL)
@@ -393,7 +378,6 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
 		EphyLocationEntry *lentry = EPHY_LOCATION_ENTRY (proxy);
 		EphyCompletionModel *model;
 		GtkWidget *entry;
-		LocationEntryAction *lea;
 
 		model = ephy_completion_model_new ();
 		ephy_location_entry_set_completion (EPHY_LOCATION_ENTRY (proxy),
@@ -406,14 +390,10 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
 						    EPHY_COMPLETION_EXTRA_COL,
 						    EPHY_COMPLETION_FAVICON_COL);
 		
-		lea = g_slice_new (LocationEntryAction);
-		lea->entry = EPHY_LOCATION_ENTRY (proxy);
-		lea->action = EPHY_LOCATION_ACTION (action);
-		
 		ephy_location_entry_set_match_func (EPHY_LOCATION_ENTRY (proxy), 
 							match_func, 
-							lea,
-							destroy_match_func);
+							NULL,
+							NULL);
 
 		add_completion_actions (action, proxy);
 
