forward DP viterbi cleaning up edge cases