Refactored isPalindrome