       for container in ['overlay', 'leftside', 'rightside']
         prepareActionFor @, container
 
-    @add images if images
+    if images
+      @add images
 
     instances.push @
-
-
-
 
   close: ->
     isOpen = false
     opened = null
+
     if hasClass @overlay, choco_show
       removeClass @overlay, choco_show
       removeClass document.body, choco_body
-      removeClass @current.thumbnail, choco_selected if @options.thumbnails
+
+      if @options.thumbnails
+        removeClass @current.thumbnail, choco_selected
+
       @current = null
       pushState()
-    @
-
-
-
+
+    return @
 
   open: (cid, updateHistory) ->
-    return if isOpen
+    return @ if isOpen
+
     opened = @
     isOpen = true
+
     addClass @overlay, choco_show
     addClass document.body, choco_body
+
     @updateDimensions()
     @select cid, updateHistory
-    @
-
-
-
+
+    return @
 
   select: (item, updateHistory = true) ->
-
     if typeof item is 'number'
       item = @storage.get item
 
     return false unless item
 
     getEnv()
-
     translate @slider, env.shift * item.cid
 
     if @options.thumbnails
-
-      removeClass @current.thumbnail, choco_selected if @current?
+      if @current?
+        removeClass @current.thumbnail, choco_selected
 
       thumb = item.thumbnail
       addClass thumb, choco_selected
 
-      offset = env.w / 2 - thumb.offsetLeft - offsetWidth(thumb) / 2
-
+      offset = (env.w / 2) - thumb.offsetLeft - (offsetWidth(thumb) / 2)
       offset = squeeze offset, 0, env.w - @dimensions.thumbWidth
+
       translate @thumbnails, offset
 
     if updateHistory
-      title = if item.title then item.title else item.hashbang
-      pushState title, item.hashbang
+      pushState item.title ? item.hashbang, item.hashbang
 
     loading = hasClass item.slide, choco_loading
     if loading
-      loadImage item, (success) =>
-        @updateSides item
+      loadImage item, => @updateSides item
     else
       @updateSides item
 
     @current = item
 
-    true
-
-
-
+    return true
 
   next: ->
     @select @storage.next @current

      return false

    @options = merge defaultOptions, options

    @storage = new Storage @options.repeat

    template = templates.overlay.replace '{{thumbnails}}', if @options.thumbnails then templates.thumbnails else ''

    @overlay = beforeEnd(document.body, template)
    @slider = getTarget @overlay, ".#{choco}slider"

    isTouch = @initTouch getEnv()
    @options.thumbnails = false if isTouch

    unless isTouch

      containers = ['leftside', 'rightside']
      containers.push 'thumbnails' if @options.thumbnails

      for container in containers
        @[container] = getTarget @overlay, ".#{choco}#{container}"

      if @options.thumbnails
        @thumbnailsToggle = getTarget @overlay, ".#{choco}thumbnails-toggle"
        addEvent @thumbnailsToggle, 'click', =>
          @toggleThumbnails()
      else
        for container in ['overlay', 'leftside', 'rightside']
          addClass @[container], choco_no_thumbnails

        when 39 # Right arrow
          opened.next()

window.chocolate = Chocolate
