This whole block can be moved within the `is_valid()` block, since it's only used then.