implementation of keyed markov model