flatten trees