Update validator.js

moved some variable declarations to the top of functions.