 	maxLength = 8
 	currentModel = null
 	
-	capitalize = (string) -> string[0].toUpperCase() + string.slice(1)
+	capitalize = (string) ->
+		if string.length > 0
+			string[0].toUpperCase() + string.slice(1)
+		else ""
 	
 	generateAndShow = ->
 		$word.text capitalize generate maxLength, currentModel, n

			sum += element.frequency
			if sum >= target then return elementName
	
		# Returns the node of the probability tree (generate's "model" argument)
		# that represents the supplied sequence.  If no such node exists,
		# returns null.
	node = (sequence) ->

			unless result? then return null
		result
	
	# Don't bother trying to generate a sequence if there's nothing to generate
	# it from.
	if model.count is 0 then return ""
	
	result = ""
	
	parent = model
	
	until result.length >= maxLength or parent is null
