changed map to flatmap