modified isPalindrome method