added markov algorithm