anchor.diff:        end,
         Postpone, Hibernate, Timeout, NextEvents).
   %%
  -%% Process all action()s
  +%% Process all actions
   loop_event_actions(
  -  Parent, Debug, S, Events, Event,
  -  State, NextState, NewData, [Action|Actions],
  +  Parent, Debug, S, Events,
  +  State, NewData, P, Event, NextState, [Action|Actions],
     Postpone, Hibernate, Timeout, NextEvents) ->
       case Action of
   	%% Actual actions
  
positive.code: 	      false ->
  		  {consume,Event,NextState}
  	  end),
      %% Have a peek on the event queue so we can avoid starting
      %% the state timer unless we have to
      {Q,Timer} =
  	case Timeout of
  	    undefined ->
  		%% No state timeout has been requested
  		{Q3,undefined};
  	    {timeout,Time,EventContent} ->
  		%% A state timeout has been requested
  		case Q3 of
  		    [] when Time =:= 0 ->
  			%% Immediate timeout - simulate it
  			%% so we do not get the timeout message
  			%% after any received event
  			{[{timeout,EventContent}],undefined};
  		    [] ->
  			%% Actually start a timer
  			{Q3,erlang:start_timer(Time, self(), EventContent)};
  		    _ ->
  			%% Do not start a timer since any queued
  			%% event cancels the state timer so we pretend
  			%% that the timer has been started and cancelled
  			{Q3,undefined}
  		end
  	end,
      %% Loop to top of event queue loop; process next event
      loop_events(
        Parent, NewDebug,
        S#{
  	state := NextState,
  	data := NewData,
  	timer := Timer,
  	postponed := P,
  	hibernate := Hibernate},
        Q, Hibernate).
  
  %%---------------------------------------------------------------------------
  %% Server helpers
  
negative.code: 		true ->
  		    NewDebug = do_reply(Debug, S, From, Reply),
  		    loop_event_actions(
  		      Parent, NewDebug, S, Events,
  		      State, NewData, P, Event, NextState, Actions,
  		      Postpone, Hibernate, Timeout, NextEvents);
  		false ->
  		    NewS =
  			S#{state := State, data := NewData, postponed := P},
  		    Q = [Event|Events],
  		    ?TERMINATE(
  		       error, {bad_action,Action}, Debug, NewS, Q)
  	    end;
  	{next_event,Type,Content} ->
  	    case event_type(Type) of
  		true ->
  		    loop_event_actions(
  		      Parent, Debug, S, Events,
  		      State, NewData, P, Event, NextState, Actions,
  		      Postpone, Hibernate, Timeout,
  		      [{Type,Content}|NextEvents]);
  		false ->
  		    NewS =
  			S#{state := State, data := NewData, postponed := P},
  		    Q = [Event|Events],
  		    ?TERMINATE(
  		       error, {bad_action,Action}, Debug, NewS, Q)
  	    end;
  	%% Actions that set options
  	{postpone,NewPostpone} when is_boolean(NewPostpone) ->
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      NewPostpone, Hibernate, Timeout, NextEvents);
  	{postpone,_} ->
  	    NewS = S#{state := State, data := NewData, postponed := P},
  	    Q = [Event|Events],
  	    ?TERMINATE(
  	       error, {bad_action,Action}, Debug, NewS, Q);
  	postpone ->
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      true, Hibernate, Timeout, NextEvents);
  	{hibernate,NewHibernate} when is_boolean(NewHibernate) ->
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      Postpone, NewHibernate, Timeout, NextEvents);
  	{hibernate,_} ->
  	    NewS = S#{state := State, data := NewData, postponed := P},
  	    Q = [Event|Events],
  	    ?TERMINATE(
  	       error, {bad_action,Action}, Debug, NewS, Q);
  	hibernate ->
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      Postpone, true, Timeout, NextEvents);
  	{timeout,infinity,_} -> % Clear timer - it will never trigger
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      Postpone, Hibernate, undefined, NextEvents);
  	{timeout,Time,_} = NewTimeout when is_integer(Time), Time >= 0 ->
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      Postpone, Hibernate, NewTimeout, NextEvents);
  	{timeout,_,_} ->
  	    NewS = S#{state := State, data := NewData, postponed := P},
  	    Q = [Event|Events],
  	    ?TERMINATE(
  	       error, {bad_action,Action}, Debug, NewS, Q);
  	infinity -> % Clear timer - it will never trigger
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      Postpone, Hibernate, undefined, NextEvents);
  	Time when is_integer(Time), Time >= 0 ->
  	    NewTimeout = {timeout,Time,Time},
  	    loop_event_actions(
  	      Parent, Debug, S, Events,
  	      State, NewData, P, Event, NextState, Actions,
  	      Postpone, Hibernate, NewTimeout, NextEvents);
  	_ ->
  	    NewS = S#{state := State, data := NewData, postponed := P},
  	    Q = [Event|Events],
  	    ?TERMINATE(
  	       error, {bad_action,Action}, Debug, NewS, Q)
      end;
  %%
  %% End of actions list
  loop_event_actions(
    Parent, Debug, S, Events,
    State, NewData, P0, Event, NextState, [],
    Postpone, Hibernate, Timeout, NextEvents) ->
      %%
      %% All options have been collected and next_events are buffered.
  