first code to write text representation of tree