Updated word detection implementation.