typed flatten and added eachPair