Changes according Dominic's review notes:
- use assert_unreached
- for() loops replaced by .forEach()
- more informative variables naming
- code formatting
- tests for template element registry removed