refactor markov chain into separate module