anchor.diff:      Md5 = erlang:md5(Str),
       lists:flatten([io_lib:format("~2.16.0b", [B]) || <<B>> <= Md5]).
   
  -add_new_session(SessionTime) ->
  -    Session = random_md5(),
  -    true = ets:insert(?DB, {Session, create_expired_time(SessionTime)}),
  +
  +
  +get_session(undefined, SessionTime) ->
  +    create_session(SessionTime);
  +
  +get_session(SessionKey, SessionTime) when is_binary(SessionKey) ->
  +    get_session(binary_to_list(SessionKey), SessionTime);
  +
  +get_session(SessionKey, SessionTime) ->
  +    %%check stored session
  +    case ets:lookup(?DB, SessionKey) of
  +	[] -> create_session(SessionTime);
  +	[Session] ->
  +	    Now = now_secs(),
  +	    case Session#session.time of
  +		Time when Time < Now -> 
  +		    ets:delete(?DB, Session),
  +		    create_session(SessionTime);
  +		_E ->
  +		    Session#session{new=false}
  +	    end
  +    end.
  +
  +
  +    
  +create_session(SessionTime) ->
  +    Key = random_md5(),
  +    Dict = dict:new(),
  +    Time = create_expired_time(SessionTime),
  +    Session = #session{key=Key, dict=Dict, time=Time},
  +    true = ets:insert(?DB, Session),
       Session.
   
  +
   create_expired_time(SessionTime) ->
  -    %% {Mega, Secs, _Mili} = now(),
  -    %% Timestamp = Mega*1000000 + Secs + SessionTime. 
       now_secs() + SessionTime.
   
  -has_expired(Session) ->
  -    Now = now_secs(),
  -    case ets:lookup(?DB, Session) of
  -	[] -> true;
  -	[{Session, Time}] when Time < Now -> 
  -	    ets:delete(?DB, Session),
  -	    true;
  -	_E -> 
  -	    false
  -    end.
   
   
   now_secs() ->
  
positive.code: 
  -define(DB, ?MODULE).
  
  -define(PURGETIME, 10). %% db purge time in seconds.
  
  -record(state, {sessiontime}).
  
  
  
  
negative.code: %%--------------------------------------------------------------------
  handle_call({get_or_create, MReq}, _From, State) ->
      CReq = MReq#mreq.creq,
      {BrowserSessionKey, CReq1} = cowboy_req:cookie(?MSESSION, CReq),
      {Session, CReq2} =
  	case cowboy_req:path(CReq) of
  	    {<<"/favicon.ico">>, _} -> 
  		{#session{key=undefined, new=false}, CReq1};
  	    _Else ->
  		S = get_session(BrowserSessionKey, State#state.sessiontime),
  		io:format("session: ~p~n", [S]),
  		case S#session.new of
  		    true ->
  			NewCReq = 
  			    cowboy_req:set_resp_cookie(
  			      ?MSESSION, 
  			      S#session.key, [], CReq1),
  			{S, NewCReq};
  		    false ->
  			{S, CReq1}
  		end
  	end,
      Reply =  {ok, Session, MReq#mreq{creq=CReq2}},
      {reply, Reply, State};
  
  handle_call(_Request, _From, State) ->
  