improved the isPalindrome function