Simplifying isPalindrome function