refactored markov_chain