Make run_viterbi non-static and use extra state
Rewrite loop code to be non-static