fancy template more careful about array indices