Make naive encoding follow AST Tree