gathered some code snippets for managing multiple connections