Finished viterbi algorithm implementation