Fixed problems with duplicated variable

Used twice variable called "i".
Several problems strange problems while selecting a connection fixed.