Refactors viterbi to be more javascripty (avoid garbage collection and multiple var statements blah blah)