improve frequency analysis, refactor