Added palindrome detection logic.