refactoring set validity check