fix index calculation inside NewConnection