added bidirectional logic to connect method