Better Markov chain generator. Code cleanup.