Reorder setting up close flag
Add WaitGroup for counting connections