Add tree serialize function