Refactoring in validator.js