refactored word validation