Improved palindrome checking