C Encode WIP refactoring