anchor.diff:  %%                                   {stop, Reason, State}
   %% @end
   %%--------------------------------------------------------------------
  -handle_info({jet, Socket, Msg},
  -						#state{
  -							 socket = Socket,
  -							 name = Name} = State)
  -	when
  -		element(2, Msg) =:= Name
  -		->
  -	NewState1 = case catch handle_xmpp(Msg, State) of
  +handle_info(
  +			{jet, Socket, Msg},
  +			#state{
  +				module = Module,
  +				mod_state = ModState,
  +				socket = Socket} = State) ->
  +	lager:debug("handling message ~p", [Msg]),
  +	{ok, Callback, Args} = case catch get_callback(Msg) of
  +		{ok, C, A} -> {ok, C, A};
  +		{ok, C} -> {ok, C, []};
  +		_				->
  +			lager:warning("callback not defined for ~p", [Msg]),
  +			{ok, handle_message, [Msg]}
  +	end,
  +	lager:debug("calling ~p:~p(~p)", [Module, Callback, [Msg | Args] ++ [ModState]]),
  +	Answer = case catch erlang:apply(Module, Callback, [Msg | Args] ++ [ModState]) of
   		{reply, Reply, NewState} ->
  -			send(Socket, iolist_to_binary(Reply)),
  -			NewState;
  -		{noreply, NewState} -> NewState
  +			{reply, reply(Msg, Reply), NewState};
  +		{noreply, NewState} ->
  +			{noreply, NewState};
  +		{'EXIT', Reason} ->
  +			lager:warning("exception in ~p:~p(~p) ~p", [Module, Callback, [Msg | Args] ++ [ModState], Reason]),
  +			Reply = reply(Msg, [
  +							"<error type='cancel'>",
  +							"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>",
  +							"</error>"
  +						 ]),
  +			{reply, Reply, State}
   	end,
  -	{noreply, NewState1};
  +	NewState1 = case Answer of
  +		{noreply, NS}	->
  +			NS;
  +		{reply, R, NS} ->
  +			send(Socket, iolist_to_binary([R])),
  +			NS
  +	end,
  +	{noreply, State#state{mod_state = NewState1}};
   
   handle_info({'EXIT', Socket, Reason}, #state{socket = Socket} = State) ->
   	{stop, Reason, State};
   
   handle_info(_Info, State) ->
  -	lager:warning("unhandled info msg ~p", [_Info]),
  -	{noreply, State}.
  -
  -handle_xmpp(#iq{
  -							 q = {"query", "http://jabber.org/protocol/disco#info"},
  -							 type = "get"
  -							} = Msg,
  -						State) ->
  -	lager:debug("disco#info"),
  -	Reply = reply(Msg, [ 
  -											"<identity category='gateway' ",
  -											"type='skype' ",
  -											"name='Skype Gateway'/>",
  -											"<feature var='http://jabber.org/protocol/disco#info'/>",
  -											"<feature var='jabber:iq:register'/>"
  -										 ]),
  -	{reply, Reply, State};
  -
  -handle_xmpp(#iq{
  -							 q = {"query", "jabber:iq:register"},
  -							 type = "get"
  -							} = Msg,
  -						State) ->
  -	lager:debug("get jabber:iq:register"),
  -	Reply = reply_success(Msg),
  -	%	{ok, Str} = reply(Msg,
  -	%										[
  -	%										 "<instructions>",
  -	%										 "Press any key."
  -	%										 "</instructions>"]),
  -	{reply, Reply, State};
  -
  -handle_xmpp(#iq{
  -							 q = {"query", "http://jabber.org/protocol/disco#items"},
  -							 type = "get"
  -							} = Msg,
  -						State) ->
  -	lager:debug("get jabber:iq:register"),
  -	Reply = reply_success(Msg),
  -	%	{ok, Str} = reply(Msg,
  -	%										[
  -	%										 "<instructions>",
  -	%										 "Press any key."
  -	%										 "</instructions>"]),
  -	{reply, Reply, State};
  -
  -handle_xmpp(#iq{
  -							 from = From,
  -							 to = Name,
  -							 q = {"query", "jabber:iq:register"},
  -							 remove = undefined,
  -							 type = "set"
  -							} = Msg,
  -						State) ->
  -	lager:debug("set jabber:iq:register"),
  -	[JID, _] = re:split(From, "/"),
  -	Msg1 = reply_success(Msg),
  -	Msg2 = [
  -					"<presence type='subscribe' "
  -					"from='", Name, "' ",
  -					"to='", JID, "'>",
  -					"<nick>Skype transport</nick></presence>"
  -				 ],
  -	{reply, [Msg1, Msg2], State};
  -
  -handle_xmpp(#iq{
  -							 q = {"query","jabber:iq:gateway"},
  -							 type = "get"
  -							} = Msg,
  -						State) ->
  -	Reply = reply(Msg, [
  -											"<desc>Enter skype login</desc>",
  -											"<login>Skype login</login>",
  -											"<email>Email</email>"
  -										 ]),
  -	{reply, Reply, State};
  -
  -%handle_xmpp(#iq{
  -%							 q = {"prompt","jabber:iq:gateway"},
  -%							 type = "set"
  -%							} = Msg,
  -%						State) ->
  -%	Reply = reply(Msg, [
  -
  -handle_xmpp(#presence{
  -							 type = "subscribe",
  -							 from = From,
  -							 to = Name
  -							},
  -						State) ->
  -	lager:debug("presence subscribe"),
  -	Reply = [
  -				 "<presence type='subscribed' ",
  -				 "from='", Name, "' ",
  -				 "to='", From, "'/>"
  -				],
  -	{reply, Reply, State};
  -
  -handle_xmpp(#iq{q = {"vCard", _}} = Msg, State) ->
  -	{reply, reply(Msg, ["<NICKNAME>Skype transport</NICKNAME>"]), State};
  -
  -handle_xmpp(#iq{} = Msg, State) ->
  -	lager:debug("unhandled iq msg ~p", [Msg]),
  -	{reply, reply_error(Msg), State};
  -
  -handle_xmpp(Msg, State) ->
  -	lager:debug("unhandled xmpp msg ~p", [Msg]),
  +	lager:warning("unhandled info msg ~p when ~p", [_Info, State]),
   	{noreply, State}.
   
   %%--------------------------------------------------------------------
  
positive.code: 
  %% API
  -export([start_link/4]).
  
  %% gen_server callbacks
  -export([init/1,
  				 handle_call/3,
  				 handle_cast/2,
  				 handle_info/2,
  				 terminate/2,
  				 code_change/3]).
  
  -record(state, {socket, name}).
  
  -include("messages.hrl").
  
  %%%===================================================================
  %%% API
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @doc
  
negative.code: 							"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>",
  							"</error>"
  						 ]).
  
  
  %%%===================================================================
  %%% Getting callback function and arguments
  %%%===================================================================
  get_callback(#iq{
  				q = {"query", "http://jabber.org/protocol/disco#info"},
  				type = "get"
  				}) ->
  	{ok, disco_info};
  
  get_callback(#iq{
  				q = {"query", "jabber:iq:register"},
  				type = "get"
  				}) ->
  	{ok, register_info};
  %	lager:debug("get jabber:iq:register"),
  %	Reply = reply_success(Msg),
  	%	{ok, Str} = reply(Msg,
  	%										[
  	%										 "<instructions>",
  	%										 "Press any key."
  	%										 "</instructions>"]),
  %	{reply, Reply, State};
  
  %get_callback(#iq{
  %				q = {"query", "http://jabber.org/protocol/disco#items"},
  %				type = "get"
  %				}) ->
  %	{ok, disco_items};
  
  %get_callback(#iq{
  %				from = From,
  %				to = Name,
  %				q = {"query", "jabber:iq:register"},
  %				remove = undefined,
  %				type = "set"
  %				}) ->
  %	{ok, register};
  
  %get_callback(#iq{
  %				q = {"query","jabber:iq:gateway"},
  %				type = "get"
  %				} = Msg) ->
  %	Reply = reply(Msg, [
  %											"<desc>Enter skype login</desc>",
  %											"<login>Skype login</login>",
  %											"<email>Email</email>"
  %										 ]),
  %	{ok,  xmpp_address};
  
  %get_callback(#iq{
  %							 q = {"prompt","jabber:iq:gateway"},
  %							 type = "set"
  %							} = Msg,
  %						State) ->
  %	Reply = reply(Msg, [
  
  %get_callback(#presence{
  %				type = "subscribe",
  %				from = From,
  %				to = Name
  %				}) ->
  %	lager:debug("presence subscribe"),
  %	Reply = [
  %			"<presence type='subscribed' ",
  %			"from='", Name, "' ",
  %			"to='", From, "'/>"
  %			],
  %	{ok, presence};
  
  get_callback(#iq{q = {"vCard", _}} = Msg) ->
  	reply(Msg, ["<NICKNAME>Skype transport</NICKNAME>"]),
  	{ok, vcard}.
  