Converting from Lists to Trees