     activeSegments = _.sortBy(activeSegments, (s) -> -s.size)
     threeEndValues = []
     sortedEnds = _.sortBy(mission.possibleEnds, (s) -> -s.probability)
-    for f in [0...Math.min(3, sortedEnds.length)]
+    for f in [0...Math.min(maxRewardedEndSegments, sortedEnds.length)]
       threeEndValues.push sortedEnds[f].id 
 
     for segment in activeSegments


    if customTime?
      relativeTime = customTime

    shadowOffsetX = 0 unless shadowOffsetX
    shadowOffsetY = 0 unless shadowOffsetY

    shadowColor : "\"rgba(0, 0, 255, 0.3)\""
    mergeSegments : "true, false (default)"
    minSize : "Number"
    maxRewardedEndSegments : "Number"


  constructor : () ->


  execute : ({ input : { rgba, segments, relativeTime, dimensions, mission }, maxRewardedEndSegments, minSize, startShape, fillColor, strokeColor, hitMode, lineWidth, colorRandom, customTime, reverse, endPosition, size, shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor, mergeSegments}) ->

    width = dimensions[0]
    height = dimensions[1]
