replaced map and then flatten by flatMap, duh