Refactored MarkovGenerator to remove code duplication.