Sharing more code between encode and decode (bis)