better connection handling