Put from_tree/to_tree back into a single function