Fix bug where SVG output would sometimes have extra </g> tag