Refactor validation into validator.js