Use itertools.product to save some nesting depth