Fixed markov algorithm and added test