Fixed problem with template not being closed due to a script