fix safeConnect function

Make sure we don't visit nodes over and over again in the existsPath
helper function.

Change-Id: I8914cfebeac0f67e9b833b3a21724d0db3c2aba2
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>