added flatmap function