added markov chain, expanded logic a bit