implement hmm phmm