refactorin: using sorted letters as key