Fix bug: move for loop inside if in checkConnections

Signed-off-by: Philip Luyckx <philip.luyckx@gmail.com>