refactoring keyword_statistics.py