refine talk algorithm, add tree output