Added closing ifs in templates