  		     percent_cutoff, weight_cutoff, order,
  		     sort_key, sort_by, sort_value_forward, time_limit, NULL,
 -		     local_stats, wt.get(), matchspies.spies, false, false);
-+		     local_stats, wt.get(), matchstate_->spies, false, false);
++		     local_stats, matchstate_->wt, matchstate_->spies, false, false);
++    matchstate_->db = db_;
  
      send_message(REPLY_STATS, serialise_stats(local_stats));
  

 	    if (type >= sizeof(dispatch)/sizeof(dispatch[0]) || !dispatch[type]) {
 		string errmsg("Unexpected message type ");
 		errmsg += str(type);
@@ -226,18 +186,22 @@ RemoteServer::run()
 	    // connection.
 	    throw;
 	}

-    p = message.c_str();
-    p_end = p + message.size();
+    required_type = MSG_GETMSET;
+}
+
+void
