refactoring and a small fix for frequency analysis, its even narrow than before
refactoring and a small fix for frequency analysis, its even narrow than before