replaced match with flatMap