extracting flatmap fn