Refactor Markov plugin