 
   constructor: ->
     @chars = {}
+    @total = 0
 
   # add a single character
   add: (char) =>
     @chars[char] ||= 0
     @chars[char] += 1
+    @total += 1
 
   chars:
     @chars
 
   # sum up all the character values
   total: =>
-    (val for char,val of @chars).reduce (t, s) -> t + s
+    @total
 
   # select a character based on a random value compared with the
-  # character probability factor
+  # character probability factorposition
   #
   # for example, assuming a structure of
   # a: 22


  constructor: (corpora, dictionary, lookback = 2) ->
    @content = ""
    @loadCorpora corpora
    $.get dictionary, {}, (data) => @dictionary = data if dictionary
    @lookback = lookback
    @words = {}
    @chain = new Chain(@lookback)
    @makeWords()

  loadCorpora: (corpora) =>
    $.get('/language/corpus/load', {corpus: corpus}, (data) => @content += data)  for corpus in corpora

  makeWords: =>
    (english, madeUp) ->  @words[english] = madeUp for english, madeUp in [].push [word, @makeWord()] for word of @dictionary
    @words

  makeWord: =>
    word = ""
    key = []
    key.push new StartWord for i in [lookback..0]
    while true
      char = @chain[key].choice()
      if typeof char == 'EndWord'
        break
      word += char

  add: (string) =>
    @key = []
    @key.push new StartWord() for i in [@lookback..0]
    @addChar char for char in string.replace(/[0-9\.,-\/#!$%\^&\*;:{}=\-_~()]/g,"").toLowerCase()

  addChar: (char) =>
    @store[@key] ||= new CharList()
    @store[@key].add char
    @key.push(char)
    @key.shift()

# Markov chain representation using a Markov Chain implementation to
# make fantasy words from list of corpora.
