Split template deletion query into two