Validation code refactored