refactor longest palindromic substring