implement markovchain