Template Repeater Template Display Glitch

I am running a nightly build of 8.1. I need the nightly build due to needing some system.opcua functions.

I am having an issue with a template repeater and a template that seems to display incorrectly even though the generated data looks good. I have bound a function on the dataset of the template repeater. This dataset is updated when certain tags change.

Here is the bind for the template repeater:

runScript("self.buildDataSet",0,tag("[default]Machines/"+{MachineStatus.serverName}+"/Program/SegmentCount"),tag("[default]Machines/"+{MachineStatus.serverName}+"/Program/CurrentSegment"))

This calls the buildDataSet function:

def buildDataSet(self, segmentMax, currentSegment):
        headers = ["segmentNumber", "segmentMax", "currentSegment"]
	build = True
	try:
		segmentMax = int(segmentMax)
		currentSegment = int(currentSegment)
	except:		
		segmentMax = 3
		currentSegment = -1
		
	data = [[i, segmentMax, currentSegment] for i in xrange(segmentMax)]
	dataset = system.dataset.toDataSet(headers, data)
	
	system.tag.configure("[default]", opcuaServer.genHistoryTag("testtag"))
	system.tag.writeBlocking(["[default]testtag"],[dataset])
	return dataset

The template itself takes these parameters from the dataset and this expression is bound to the imagePath of an Image component:

case({WeldSegment.segmentNumber}, 
     0, "Amet/xmgui/seg0000.png",
 	 {WeldSegment.segmentMax}-1, "Amet/xmgui/seg0002.png",
	"Amet/xmgui/seg0001.png")

The data I write to a test tag during the buildDataSet call to see what it is actually sending to the template repeater:

0	3	-1
1	3	-1
2	3	-1

So the result should look like (and it does most of the time):
template_normal

But occasionally it looks like this:
template_glitch
When it looks like this the dataset looks the same.
But the templates that are repeated are acting like they got only zeros (0,0,0) in the first column of data instead of 0,1,2.

I am not sure how to address this.