[FIX] avoid updates of context dictionary, use a copy instead

In many methods, the context dictionary passed as a parameter is updated
in-place. This is bad practice, as these side-effects are silent but visible.
This is why the new framework uses "frozendict" for contexts. This patch fixes
some code that modifies context in-place, by modifying a copy of context instead.