 
   coll = db.collection 'rtc'
 
-  # stat helper
+  # abstraction for mapReduce page calls
 
   add_map_reduce_stat = (name, map, reduce) =>
     path = '/stats/' + name + '.json'
 
     page_fun = (req, res) =>
+      # fetch various options from the request
+
       get_int = (key, fallback) =>
         if req.param(key)?
           return parseInt(req.param(key))

      scope.min_peak = get_int('min_peak', 0)
      scope.max_peak = get_int('max_peak', Number.MAX_VALUE)

      scope.adjust_time = (time) =>
        if scale
          return time - time % scale
        else if steps?
          last = start
          for step in steps
            if step <= time
              return step
        else
          return time

      options =
        out:

            $gte: start,
            $lt: end,

      # finally call mapReduce ...

      coll.mapReduce map, reduce, options, (err, result) =>
        # this should not happen
        if err
          res.send({error: err})
          return

        # transform array into object

        data = {}

        for item in result
          data[item._id] = item.value

        # finished, send to user

        res.send data

    # callable as post and get

    app.get path, page_fun
    app.post path, page_fun
