Add HMM and modify bugs