using flatten instead of flatmap