refactoring the markov program