final version of doViterbi