Improve is_palindrome function