Added more efficient way to detect palindromes