Anagram sort algorithm refactored again