changing async forEach to forEachSeries so that middleware executes synchronously