Initial implementation of cartesian product algorithm