simpler version of viterbi algorithm