 
     @isDragging = false
     if @dragOffset
+      cos = Math.cos @dragAngle
+      sin = Math.sin @dragAngle
+
+      # Rotate the grabOffset to calculate translation correction after
+      # changing the transform origin
+      correction =
+        x: @grabOffset.x - (@grabOffset.x * cos - @grabOffset.y * sin)
+        y: @grabOffset.y - (@grabOffset.x * sin + @grabOffset.y * cos)
+
+      @$box.css "transform-origin", ""
+      @$box.css "transform", """
+        translate(#{@dragOffset.x + correction.x}px, #{@dragOffset.y + correction.y}px)
+        rotate(#{@dragAngle}rad)
+      """
+
+      # Rotate back to the closest 90 degree multiple
+      deg =  @dragAngle / Math.PI * 180
+      if deg %% 90 > 45
+        deg += 90 - deg %% 90
+      else
+        deg -= deg %% 90
+
       bounce = new Bounce()
-      bounce.translate
+      bounce.translate(
         stiffness: 1.5
-        from: @dragOffset
+        from:
+          x: @dragOffset.x + correction.x
+          y: @dragOffset.y + correction.y
         to: { x: 0, y: 0 }
+      ).rotate(
+        stiffness: 0.5
+        from: @dragAngle / Math.PI * 180
+        to: deg
+      )
 
       @playAnimation bounceObject: bounce, duration: 600
       _.defer => @$box.css "transform", ""
+      setTimeout (=> @$result.removeClass "animate"), 610
 
-    $(document).off "mousemove.boxdrag"
+    $(document).off ".boxdrag"
     $("body").removeClass "dragging"
 
   boxDrag: (e) =>

      x: e.clientX - @dragStartPos.x
      y: e.clientY - @dragStartPos.y

    distance = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2))
    constrainedDistance = distance * Math.pow(Math.E, -0.002 * distance)

    angle = Math.atan2 delta.y, delta.x
    @dragOffset =
      x: Math.cos(angle) * constrainedDistance
      y: Math.sin(angle) * constrainedDistance

    @$box.css "transform", "translate(#{@dragOffset.x}px, #{@dragOffset.y}px"

module.exports = App
      x: e.clientX
      y: e.clientY

    @boxStartPos =
      x: @$box.offset().left + @$box.width() / 2
      y: @$box.offset().top + @$box.height() / 2

    @grabOffset =
      x: e.offsetX - @$box.width() / 2
      y: e.offsetY - @$box.height() / 2

    @grabDistance = Math.sqrt \
      @grabOffset.x ** 2 + @grabOffset.y ** 2

    @$box.css "transform-origin", "#{e.offsetX}px #{e.offsetY}px"

    @dragOffset = null

    $(document).on
