TRENDOUTPUT: Optimize writing using for-each not loops