added flatMap support