Fixed comparison in loop

The old code would add all the devices n x n times because the incorrect comparison.