Refactoring, event closing, templates fixes