ENH Speed up and simplify cartesian product