refactor Cartesian product code to a sub
Merge pull request #176 from rns/fix_175

refactor Cartesian product code to a sub