Fixed some minor bugs

Fixed some minor bugs in the template and event engine.