Refactor checking for anagram to method.