Refactored the validator code.