initially had for loop to iterate though template, now used RegExp, global