refactor code and add 'longest palindromic substring'