fixed event handling, add templates