Added if check on expressions before looping through possible empty set, added tag removal for unmatched template tags