diff --git a/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike b/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike
index f93769b41b55de2bf093a40c70e64ae955d8f154..5d1079491d226f080063bd5d348ba46bec78eb85 100644
--- a/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike
+++ b/lib/modules/Protocols.pmod/LysKOM.pmod/Raw.pike
@@ -27,9 +27,21 @@ object con;
 string buf="";
 
 /* outstanding calls */
+// static private
 mapping(int:function(string:void)) async=([]);
 int ref=1;
 
+int raw_serial=lambda()
+{
+#if constant(LYSKOM_RAW)
+  add_constant("LysKOM_RAW",LysKOM_RAW+1);
+  return LysKOM_RAW+1;
+#else
+  add_constant("LysKOM_RAW",1);
+  return 0;
+#endif
+}();
+
 /* asynchronous messages callback list */
 mapping(int:array(function(string:void))) async_callbacks=([]);
 
@@ -55,6 +67,8 @@ static inline int conwrite(string what)
    return i;
 }
 
+array komih�g=({});
+
 class Send
 {
    int ref;
@@ -71,8 +85,13 @@ class Send
    void write()
    {
       out_req++;
-      conwrite(ref+" "+request+"\r\n");
       async[ref]=callback;
+      conwrite(ref+" "+request+"\r\n");
+#ifdef LYSKOM_DEBUG
+//       werror("LYSKOM "+raw_serial+" inserting callback %O for call %d\n",callback,ref);
+//       werror("async: %O\n",async);
+#endif
+      komih�g+=({function_object(callback)});
    }
 }
 
@@ -124,6 +143,10 @@ mixed sync_do(int ref,string|void request)
       {
 	 if (!async[ref])
 	    error("request ref %d not in queue, but no callback\n",ref);
+#ifdef LYSKOM_DEBUG
+// 	 werror("LYSKOM "+raw_serial+" removing callback %O for call %d (handling ref %d in sync mode)\n",
+// 		async[ref],ref);
+#endif
 	 m_delete(async,ref);
       }
       else
@@ -471,14 +494,20 @@ array(array(mixed)|int) try_parse(string what)
 
 void got_reply(int ref,object|array what)
 {
+//   werror("got_reply(): async: %O\n",async);
    function call=async[ref];
+#ifdef LYSKOM_DEBUG
+//    werror("LYSKOM "+raw_serial+" removing callback %O for call %d\n",call,ref);
+#endif
+   m_delete(async,ref);
    if (!call)
    {
-      werror("LysKOM.Raw: lost callback for call %d\n",ref);
+      werror("LysKOM.Raw: lost callback for call %d %s\n",ref,
+	     zero_type(call)?"(lost from mapping??!)":"(zero value in mapping)");
+      //      werror("komih�g: %O\n",komih�g);
       werror(master()->describe_backtrace(backtrace()));
       return;
    }
-   m_delete(async,ref);
 #if constant(thread_create) && !LYSKOM_UNTHREADED
    call_fifo->write( ({call,what}) );
 #else
diff --git a/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike b/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike
index 178b4c9218599b1c9e279c7dfb3bbda025c419c4..b9de8eb588d94e384a34e63a4b66b8eb4f5ebf62 100644
--- a/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike
+++ b/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike
@@ -1,4 +1,4 @@
-//  $Id: Session.pike,v 1.11 1999/10/17 00:57:54 js Exp $
+//  $Id: Session.pike,v 1.12 1999/10/18 21:53:09 js Exp $
 //! module Protocols
 //! submodule LysKOM
 //! class Session
@@ -482,7 +482,10 @@ class Text
          case "creation_time":
 	   waitfor_stat();
 	   return _stat->creation_time;
-	
+
+         case "clear_stat":
+           _stat=0;
+	   return 0;
 
          case "mark_as_read":
             return mark_as_read;
@@ -686,6 +689,9 @@ class Person
 	 case "unread":
 	    waitfor_unread();
 	    return _unread;
+	 case "clear_membership":
+            _membership=0;
+	    return 0;
 	 case "membership":
 	    waitfor_membership();
 	    return _membership;
diff --git a/lib/modules/Protocols.pmod/LysKOM.pmod/Threads.pike b/lib/modules/Protocols.pmod/LysKOM.pmod/Threads.pike
index 0cc523dbff418e86ef76f749cfc1352ec7a825ac..8f6d77856e28cf6cf09b090739a51cd3f5732a35 100644
--- a/lib/modules/Protocols.pmod/LysKOM.pmod/Threads.pike
+++ b/lib/modules/Protocols.pmod/LysKOM.pmod/Threads.pike
@@ -79,6 +79,7 @@ class Thread
       conf_no=_conf_no;
       
       textno_to_node[text->no]=this_object();
+      _text->clear_stat;
 
       unread=unread_numbers[text->no];
       if(!unread)