little refactoring for validator (special thanks to batigol) :)