refactor anagrams