Added viterbi logic