Code refactoring for word palindrome