refactored and added memoization on token frequencies
new file created in refactoring