Fix/codec encode context

this fixes #1523 
Oh I see @x was used in other parts of the code before this patch.