clean up code, use cartesian product