added connection handling