reworked templates and event handling