refactoring validate method