 
   # Private
 
+  getVariantForName: (name) =>
+    (v for v in @variants when v.name is name)[0]
+
+  chooseVariant: (variant) =>
+    variant?.callback?()
+    @chosen = variant
+
   recordStart: (variant) =>
     # Record which experiment was run on the server
     request(

    request("#{@endpoint}/complete", experiment: @name, variant: name)

  # Variant Cookie

  getVariantCookie: =>
    getCookie("abbaVariant_#{@name}")

    this

  start: (name, options = {}) =>
    if variant = @getPreviousVariant()
      # Use the same variant as before, don't record anything
      @chooseVariant(variant)
      return this

    if name?
      # Custom variant provided
      variant = @getVariantForName(name)
      variant or=
        name:    name
        control: options.control

    else
      # Or choose a random one
      random  = Math.floor(Math.random() * @variants.length)
      variant = @variants[random]

    throw new Error('No variants added') unless variant
    @recordStart(variant)
    @chooseVariant(variant)
    this

  complete: (name) =>
    # Optionally pass a name, or read from the cookie
    name or= @getVariantCookie()
