First draft of the Viterbi algorithm