working version of hmm