merge
clean up and process tree code