refactor and polish validator