Index: branches/stable/cgi-bin/main.cgi
===================================================================
--- branches/stable/cgi-bin/main.cgi	(revision 49)
+++ branches/stable/cgi-bin/main.cgi	(revision 50)
@@ -1482,5 +1482,6 @@
 
 	# Set up query for compacting free blocks.
-	$sth = $ip_dbh->prepare("select * from freeblocks where city='$webvar{city}'".
+	$sth = $ip_dbh->prepare("select * from freeblocks where cidr << ".
+		"(select cidr from routed where cidr >> '$cidr') ".
 		" and maskbits<=".$cidr->masklen." and routed='y' order by maskbits desc");
 
@@ -1528,5 +1529,5 @@
       } else {
 	$sth = $ip_dbh->prepare("insert into freeblocks values ('$cidr',".$cidr->masklen.
-		",'$webvar{city}','y')");
+		",(select city from routed where cidr >>= '$cidr'),'y')");
       }
       $sth->execute;
