improved performance in aggregate.js
only look for variables once instead of every loop iteration