Use FlatMap directly to remove unnecessary iteration.