rewrite tree decode