fixed index out of bounds in ReTemplate.Output