re-used functions in replace_infreq, refactored and added code for Viterbi Algorithm tagging