how to flatten the nested list