Refactoring codec WIP 4