improve palindrome function