finalized Palindrome algorithm