Rough code for tree-to-list