Working Version of HMM