anchor.diff:  clean_triggers(Triggers,IDs) ->
     lists:filter(fun({ID,_})->not lists:member(ID,IDs) end, Triggers).
   
  -%%exit if What is jailed
  +check_jailed(LD,_) when ?max_jailed < length(LD#ld.jailed) ->
  +  % we take a timeout when enough pids are jailed. conservative is good.
  +  erlang:start_timer(timeout(restart), self(), restart),
  +  stop_monitor(),
  +  flush(),
  +  throw(taking_timeout);
   check_jailed(LD,What) ->
  -  false = lists:member(What, LD#ld.jailed),
  -  erlang:start_timer(timeout(release), self(), {release, What}),
  -  LD#ld{jailed=[What|LD#ld.jailed]}.
  +  case lists:member(What, LD#ld.jailed) of
  +    false-> 
  +      erlang:start_timer(timeout(release), self(), {release, What}),
  +      LD#ld{jailed=[What|LD#ld.jailed]};
  +    true -> 
  +      throw(is_jailed)
  +    end.
   
   do_mon(LD) ->
     send_report(LD,sysMon),
  
positive.code: %% api
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  start() -> 
    Init = fun(D) -> fun() -> init(D) end end,       % mmm.... haskell....
    {Pid,Ref} = erlang:spawn_monitor(Init(self())), 
    receive
      {Pid,ok} -> erlang:demonitor(Ref,[flush]),Pid;
      {'DOWN',Ref,_,Pid,OldPid} -> OldPid
    end.
  
  stop() -> 
    send_to_wd(stop).
  
  add_proc_subscriber(Pid) when is_pid(Pid) ->
    case is_process_alive(Pid) of
      true -> send_to_wd({add_subscriber,mk_send(Pid)});
      false-> {error,no_such_pid}
    end;
  add_proc_subscriber(Reg) when is_atom(Reg) ->
    send_to_wd({add_subscriber,mk_send(Reg)});
  add_proc_subscriber({Reg,Node}) when is_atom(Reg),is_atom(Node) ->
    send_to_wd({add_subscriber,mk_send({Reg,Node})}).
  
  %% E.g:  watchdog:add_send_subscriber(tcp,"localhost",56669,"I'm a Cookie").
  %% it's possible to add the same subscriber twice. this is a bug.
  add_send_subscriber(Proto,Host,Port,PassPhrase) ->
    case inet:gethostbyname(Host) of
      {ok,{hostent,Host,[],inet,4,_}} -> 
        send_to_wd({add_subscriber,mk_send(Proto,Host,Port,PassPhrase)});
      {ok,{hostent,G,[W],inet,4,_}} -> {error,{badhost,W,G}};
      {ok,R}                        -> {error,R};
      {error,R}                     -> {error,R}
    end.
  
  add_log_subscriber() ->
    try ?MODULE ! {add_subscriber,mk_log(group_leader())}, ok
    catch _:R -> {error,R}
    end.
  
  clear_subscribers() ->
    try ?MODULE ! clear_subscribers, ok
    catch _:R -> {error,R}
    end.
  
  message(Term) ->
    try ?MODULE ! {user,Term}, ok
    catch C:R -> {C,R}
    end.
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  init(Daddy) ->
    try register(?MODULE,self()), 
        Daddy ! {self(),ok}
    catch _:_ -> exit(whereis(?MODULE))
    end,
    LD = #ld{prfState=prfTarg:subscribe(node(),self(),[prfSys,prfPrc])},
    start_monitor(LD#ld.triggers),
    loop(LD).
  
  loop(LD) when ?max_jailed < length(LD#ld.jailed) ->
    %% we take a timeout when enough pids are jailed. conservative is good.
    erlang:start_timer(timeout(restart), self(), restart),
    stop_monitor(),
    flush(),
    loop(LD#ld{jailed=[]});
  loop(LD) ->
    receive
      %% quit
      stop -> 
        ok;
      reload ->
        ?MODULE:loop(LD);
      print_state ->
        print_term(group_leader(),LD),
        loop(LD);
      %% set configs
      list_triggers ->
        print_term(group_leader(),LD#ld.triggers),
        loop(LD);
      {del_trigger,ID} ->
        loop(LD#ld{triggers=del_trigger(LD#ld.triggers,ID)});
      {add_trigger,{ID,Fun}} ->
        loop(LD#ld{triggers=add_trigger(LD#ld.triggers,ID,Fun)});
      list_subscribers ->
        print_term(group_leader(),LD#ld.subscribers),
        loop(LD);
      clear_subscribers ->
        loop(LD#ld{subscribers=[]});
      {add_subscriber,Sub} ->
        loop(LD#ld{subscribers=[Sub|LD#ld.subscribers]});
      %% fake trigger for debugging
      trigger ->
        send_report(LD,test),
        loop(LD);
      %% data from user
      {user,Data} -> 
        NLD = LD#ld{userData=Data},
        loop(try do_user(check_jailed(NLD,userData)) catch _:_ -> NLD end);
      %% data from prfTarg
      {{data,_},Data} ->
        NLD = LD#ld{prfData=Data},
        loop(try do_triggers(check_jailed(NLD,prfData)) catch _:_ -> NLD end);
      %% data from system_monitor
      {monitor,Pid,Tag,Data} ->
        NLD = LD#ld{monData=[{tag,Tag},{pid,Pid},{data,Data}]},
        loop(try do_mon(check_jailed(NLD,Pid)) catch _:_ -> NLD end);
      %% restarting after timeout
      {timeout, _, restart} -> 
        start_monitor(LD#ld.triggers),
        loop(LD#ld{jailed=[]});
      %% release a pid from jail
      {timeout, _, {release, Pid}} ->
        loop(LD#ld{jailed = LD#ld.jailed--[Pid]});
      X ->
        ?log({unexpected_msg,X}),
        loop(LD)
    end.
  
  start_monitor(Triggers) ->
  
negative.code: 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  mk_subscriber({pid,To},_) -> mk_send(To);
  mk_subscriber({Proto,{Host,Port}},Pwd) -> mk_send(Proto,Host,Port,Pwd);
  mk_subscriber({log,trc},FN) -> mk_log(trc,open_file(FN));
  mk_subscriber({log,text},FN) -> mk_log(text,open_file(FN));
  mk_subscriber({log,screen},_) -> mk_log(text,group_leader()).
  
  %% send subscribers
  mk_send(Where) ->
    fun(Chunk) ->
        try Where ! Chunk
  