Clean up internal logic so it only requires one index template