fixed issue with gate index calc