updated markov code