       delta = Math.ceil amount * (elapsed / duration) * calibration
       delta = if isKeyStillDown() then delta else Math.max 0, Math.min delta, amount - totalDelta
 
-      if delta and performScroll element, axisName, sign * delta
+      if delta and performScroll element, direction, sign * delta
         totalDelta += delta
         advanceAnimation()
       else
         checkVisibility element
-        cancelAnimationFrame animatorId
+        cancelAnimation()
 
     advanceAnimation()
 

# Instead, we scroll the element by 1 or -1 and see if it moved (then put it back).
# Bug verified in Chrome 38.0.2125.104.
isScrollPossible = (element, direction, amount, factor) ->
  axisName = scrollProperties[direction].axisName
  # amount, here, is treated as a relative amount, which is correct for relative scrolls. For absolute scrolls
  # (only gg, G, and friends), amount can be either 'max' or zero. In the former case, we're definitely
  # scrolling forwards, so any positive value will do for delta.  In the latter case, we're definitely
  # scrolling backwards, so a delta of -1 will do.
  delta = factor * getDimension(element, direction, amount) || -1
  delta = delta / Math.abs delta # 1 or -1
  performScroll(element, axisName, delta) and performScroll(element, axisName, -delta)

# Find the element which we should and can scroll (or document.body).
findScrollableElement = (element, direction, amount, factor = 1) ->
  axisName = scrollProperties[direction].axisName
  while element != document.body and
    not (isScrollPossible(element, direction, amount, factor) and shouldScroll(element, direction))
      element = element.parentElement || document.body

      time == activationTime

    # Store amount's sign and make amount positive; the logic is clearer when amount is positive.
    sign = Math.sign amount
    amount = Math.abs amount

    # Duration in ms. Allow a bit longer for longer scrolls.
