new version using new flatmap