Instead of `map(....).flatten`, better go for `flatMap`.