implemented the event functions
Fixed two mistakes in templates