Use output frequency and refactor codes