A tree-to-list function that is probably wrong