add hmm and  reorganize some functions