Now matches templates instead of for-each looping over elements

The code is much shorter now en still as readable