 				, 3000
 
 		$(window).on 'productAddedToCart', ->
-			promiseAdd = self.getData()
-			promiseAdd.success (data) ->
+			self.getData().success (data) ->
 				self.updateItems data
 				self.changeCartValues data
 				$(window).trigger "cartUpdated", [null, true]
 
-		promise = @getData()
-		promise.success (data) ->
-			self.insertCartItems data
-			self.changeCartValues data
-
-
-	getData: ->
-		self = this
-
-		promise = $.ajax {
+		@getData().success (data) =>
+			@insertCartItems data
+			@changeCartValues data
+
+
+	getData: =>
+		$.ajax({
 			url: "/api/checkout/pub/orderForm/"
 			data: JSON.stringify(expectedOrderFormSections: ["items", "paymentData", "totalizers"])
 			dataType: "json"
 			contentType: "application/json; charset=utf-8"
 			type: "POST"
-		}
-
-		promise.done (data) ->
-			self.options.cartData = data
-
-		promise.fail (jqXHR, textStatus, errorThrown) ->
+		})
+		.done (data) =>
+			@options.cartData = data
+		.fail (jqXHR, textStatus, errorThrown) ->
 			# console.log "Error Message: " + textStatus
 			# console.log "HTTP Error: " + errorThrown
 
-		promise
-
-	insertCartItems: (data) ->
-		self = this
-
-		if data
-			total = 0
-
-			for subtotal in data.totalizers
-				total += subtotal.value if subtotal.id is 'Items'
-
-			$('.vtexsc-text', self.options.$template).text 'R$' + self.formatCurrency(total)
-
-			self.updateItems data
-
-	deleteItem: (item) ->
-		self = this
-
+	insertCartItems: (data) =>
+		return unless data
+
+		total = 0
+		for subtotal in data.totalizers when subtotal.id is 'Items'
+			total += subtotal.value
+
+		$('.vtexsc-text', @options.$template).text 'R$' + formatCurrency(total)
+		@updateItems data
+
+	deleteItem: (item) =>
 		$(item).parent().find('.vtexsc-overlay').show()
 
-		data = JSON.stringify(
+		data = JSON.stringify
 			expectedOrderFormSections: ["items", "paymentData", "totalizers"]
 			orderItems: [
 				index: $(item).data("index")
 				quantity: 0
 			]
-		)
-
-		promise = $.ajax {
+
+		$.ajax({
 			url: "/api/checkout/pub/orderForm/" + self.options.cartData.orderFormId + "/items/update/"
 			data: data
 			dataType: "json"
 			contentType: "application/json; charset=utf-8"
 			type: "POST"
-		}
-
-		promise.success (data) ->
-			self.options.cartData = data
-			self.changeCartValues data
-			self.updateItems data
+		})
+		.success (data) =>
+			@options.cartData = data
+			@changeCartValues data
+			@updateItems data
 			$(window).trigger "cartUpdated", [data]
-
-		promise.done ->
+		.done ->
 			$(item).parent().find('.vtexsc-overlay').hide()
-
-		promise.fail (jqXHR, textStatus, errorThrown) ->
+		.fail (jqXHR, textStatus, errorThrown) ->
 			# console.log "Error Message: " + textStatus
 			# console.log "HTTP Error: " + errorThrown
 
-	updateItems: (data) ->
+	updateItems: (data) =>
+		return unless data
+
+		items = ''
+
+		for item, i in data.items
+			items += """
+			<tr>
+					<td class="cartSkuImage">
+							<a class="sku-imagem" href="#{item.detailUrl}"><img height="71" width="71" alt="#{item.name}" src="#{item.imageUrl}" /></a>
+					</td>
+					<td class="cartSkuName">
+							<h4><a href="#{item.detailUrl}">"#{item.name}"</a><br /></h4>
+					</td>
+					<td class="cartSkuPrice">
+							<div class="cartSkuUnitPrice">
+									<span class="bestPrice">R$ #{formatCurrency(item.price)}</span>
+							</div>
+					</td>
+					<td class="cartSkuQuantity">
+							<div class="cartSkuQtt">
+									<span class="cartSkuQttTxt"><span class="vtexsc-skuQtt">#{item.quantity}</span></span>
+							</div>
+					</td>
+					<td class="cartSkuActions">
+							<span class="cartSkuRemove" data-index="#{i}">
+									<a href="javascript:void(0);" class="text" style="display: none;">excluir</a>
+							</span>
+							<div class="vtexsc-overlay" style="display: none;"></div>
+					</td>
+			</tr>
+			"""
+
+		$(".vtexsc-productList tbody", @options.$template).html items
+
 		self = this
-		$template = self.options.$template
-
-		if data
-			items = ''
-
-			$(".vtexsc-productList tbody", $template).html ""
-
-			for item, i in data.items
-				item = """
-				<tr>
-						<td class="cartSkuImage">
-								<a class="sku-imagem" href="#{item.detailUrl}"><img height="71" width="71" alt="#{item.name}" src="#{item.imageUrl}" /></a>
-						</td>
-						<td class="cartSkuName">
-								<h4><a href="#{item.detailUrl}">"#{item.name}"</a><br /></h4>
-						</td>
-						<td class="cartSkuPrice">
-								<div class="cartSkuUnitPrice">
-										<span class="bestPrice">R$ #{self.formatCurrency(item.price)}</span>
-								</div>
-						</td>
-						<td class="cartSkuQuantity">
-								<div class="cartSkuQtt">
-										<span class="cartSkuQttTxt"><span class="vtexsc-skuQtt">#{item.quantity}</span></span>
-								</div>
-						</td>
-						<td class="cartSkuActions">
-								<span class="cartSkuRemove" data-index="#{i}">
-										<a href="javascript:void(0);" class="text" style="display: none;">excluir</a>
-								</span>
-								<div class="vtexsc-overlay" style="display: none;"></div>
-						</td>
-				</tr>
-				"""
-				items += item
-
-			$(".vtexsc-productList tbody", $template).html items
-
-			$(".vtexsc-productList .cartSkuRemove", $template).click ->
-				self.deleteItem(this)
-
-	changeCartValues: (data) ->
-		self = this;
-
-		if data
-			total = 0
-			for subtotal in data.totalizers
-				total += subtotal.value if subtotal.id is 'Items'
-
-			$(".vtexsc-text", self.options.$template).text "R$ " + self.formatCurrency total
-
-	formatCurrency: (value) ->
-		if value is '' or not value? or isNaN value
-			num = 0.00
-		else
-			num = value / 100
-		parseFloat(num).toFixed(2).replace('.', ',').toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.')
-
-	showMinicart: (value) ->
-		promise = @getData()
-		promise.done ->
-			self.updateItems data
+		$(".vtexsc-productList .cartSkuRemove", @options.$template).click ->
+			self.deleteItem(this)
+
+	changeCartValues: (data) =>
+		return unless data
+
+		total = 0
+		for subtotal in data.totalizers when subtotal.id is 'Items'
+			total += subtotal.value
+
+		$(".vtexsc-text", @options.$template).text "R$ " + formatCurrency total
+
+	showMinicart: (value) =>
+		@getData().done =>
+			@updateItems data
 			$(".vtexsc-cart").slideDown()
 			clearTimeout @options.timeoutToHide
 			@options.timeoutToHide = setTimeout ->
 				$(".vtexsc-cart").slideUp()
 			, 3000
 
-	$.fn[pluginName] = (options) ->
-		@each ->
-			if !$.data(this, "plugin_#{pluginName}")
-				$.data(@, "plugin_#{pluginName}", new vtexMinicart(@, options))
+
+#
+# Utils
+#
+formatCurrency: (value) ->
+	if value is '' or not value? or isNaN value
+		num = 0.00
+	else
+		num = value / 100
+	parseFloat(num).toFixed(2).replace('.', ',').toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.')
+
+
+#
+# Plugin
+#
+$.fn.vtexMinicart = (options) ->
+	@each ->
+		return 'ja tem' if $.data(this, "plugin_vtexMinicart")
+		$.data(@, "plugin_vtexMinicart", new vtexMinicart(@, options))
+	return this
+
+$.fn.vtexMinicart.defaults =
+	timeoutToHide: null
+	cartData: null
+	$template: null
 
 
 $ -> $('.portal-minicart-ref').vtexMinicart()

$ = window.jQuery

pluginName = 'vtexMinicart'
defaults = {
	timeoutToHide: null
	cartData: null
	$template: null
}

class vtexMinicart
	constructor: (@element, options) ->
		@options = $.extend {}, defaults, options

		@_defaults = defaults
		@_name = pluginName

		@init()

	init: ->
		self = this

		self.options.$template = $ """

		</div>
		"""

		$(@element).after @options.$template

		$(@options.$template)
		.mouseover ->
			$(window).trigger "miniCartMouseOver"
		.mouseout ->
