use flatMap instead of match