improve connecting logic