improve connection handling