rename i to gateIndex