Refactoring codec WIP 5