Fixes #3347 : store unexpanded and expanded version of variables for
more robust reporting

clean code