Refactored the shit out of viterbi.