Bringing foreign connection logic into the core. Committing for test on server.