Minor code cleanup: Use forEach instead of map where appropriate

* Also replaced buf with newTokens in ext.core.TemplateHandler.js

Change-Id: I81e05a13c9373aa298d710b7942f9fe3cd802e63