Improve performance of isConnectedTo