fix viterbi algorithm