refactor anagram