added robustness to hmm.py