Extracted sanitizeWord method