template gathering logic fix