pass in cncurency arg
refactor out flattern function