main logic connection handling