modified to take template variable