refactored. separated HMM specific methods to new module