updated isPalindrome with better solution