I'm not sure I quite understand the point of this `isValid` function.  Is it just a safety net to verify that what we generated is good?