Rewriting encoding code